Skip to content

Commit

Permalink
Fixed borken bilt
Browse files Browse the repository at this point in the history
  • Loading branch information
robconery committed Apr 13, 2016
1 parent 809d626 commit 09585f9
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 12 deletions.
12 changes: 5 additions & 7 deletions lib/moebius.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ defmodule Moebius do
These functions hand off to PSQL because Postgrex can't run more than
one command per query.
"""
# def run_with_psql(sql, opts) do
# db = opts[:database] || opts[:db]
# args = ["-d", db, "-c", sql, "--quiet", "--set", "ON_ERROR_STOP=1", "--no-psqlrc"]
# IO.inspect args
# System.cmd "psql", args
# end
def run_with_psql(sql, opts) do
db = opts[:database] || opts[:db]
args = ["-d", db, "-c", sql, "--quiet", "--set", "ON_ERROR_STOP=1", "--no-psqlrc"]
System.cmd "psql", args
end

def get_connection(), do: get_connection(:connection)
def get_connection(key) when is_atom(key) do
opts = Application.get_env(:moebius, key)
IO.inspect opts
cond do
Keyword.has_key?(opts, :url) -> Keyword.merge(opts, parse_connection(opts[:url]))
true -> opts
Expand Down
73 changes: 68 additions & 5 deletions test/test_helper.exs
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")

0 comments on commit 09585f9

Please sign in to comment.