-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
73 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,74 @@ | ||
ExUnit.start() | ||
defmodule TestDb, do: use Moebius.Database | ||
import Moebius.Query | ||
|
||
worker = Supervisor.Spec.worker(TestDb, [Moebius.get_connection(:test_db)]) | ||
|
||
worker = Supervisor.Spec.worker(TestDb, [Moebius.get_connection]) | ||
Supervisor.start_link [worker], strategy: :one_for_one | ||
|
||
IO.inspect "Dropping and reloading db..." | ||
sql_file(:test_schema) |> TestDb.first | ||
IO.inspect "Here we go..." | ||
schema_sql = """ | ||
drop index if exists idx_docs; | ||
drop table if exists user_docs; | ||
drop table if exists logs; | ||
drop table if exists users; | ||
drop table if exists products; | ||
drop table if exists date_night; | ||
create table users( | ||
id serial primary key, | ||
email varchar(50) unique not null, | ||
first varchar(50), | ||
last varchar(50), | ||
order_count integer not null default 10, | ||
profile jsonb | ||
); | ||
create table products( | ||
id serial primary key not null, | ||
sku varchar(50) not null, | ||
name varchar(255) not null, | ||
price decimal(10,2) not null default 0, | ||
description text, | ||
search tsvector, | ||
variants jsonb | ||
); | ||
create table logs( | ||
id serial primary key not null, | ||
user_id integer references users(id), | ||
log text | ||
); | ||
create table user_docs( | ||
id serial primary key not null, | ||
body jsonb not null, | ||
created_at timestamptz default now(), | ||
updated_at timestamptz | ||
); | ||
create index idx_docs on user_docs using GIN(body jsonb_path_ops); | ||
insert into users(email, first, last) values('[email protected]','Rob','Blah'); | ||
insert into users(email, first, last) values('[email protected]','Jill','Gloop'); | ||
insert into users(email, first, last) values('[email protected]','Mary','Muggtler'); | ||
insert into users(email, first, last) values('[email protected]','Mike','Ghruoisl'); | ||
create table date_night(id serial primary key, date timestamptz); | ||
insert into date_night(date) values(now()); | ||
insert into date_night(date) values(now() - '1 day' :: interval); | ||
insert into date_night(date) values(now() + '2 days' :: interval); | ||
insert into date_night(date) values(now() + '1 year' :: interval); | ||
drop table if exists sessions; | ||
create table sessions( | ||
id varchar(36) primary key not null, | ||
body jsonb not null, | ||
search tsvector, | ||
created_at timestamptz not null default now(), | ||
updated_at timestamptz | ||
); | ||
create index idx_sessions_search on sessions using GIN(search); | ||
create index idx_sessions on sessions using GIN(body jsonb_path_ops); | ||
""" | ||
Moebius.run_with_psql(schema_sql, db: "meebuss") |