Skip to content

Commit

Permalink
Add scripts for initializing the DB
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniskalou committed Aug 11, 2017
1 parent e342d49 commit fcc4fd2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ logs
_build
.idea
rebar3.crashdump

datadir
2 changes: 2 additions & 0 deletions scripts/populate_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo "CREATE DATABASE ${USER};" | psql -h 127.0.0.1 -p 10432 template1
psql -h 127.0.0.1 -p 10432 template1 < test/data/test_schema.sql
8 changes: 8 additions & 0 deletions scripts/setup_test_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

if [ -z $(which initdb) ] ; then
echo "Postgres not found, you may need to add /usr/lib/postgresql/<version>/bin to PATH."
exit 1
fi

initdb --locale en_US.UTF-8 datadir
10 changes: 10 additions & 0 deletions scripts/start_test_db.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

if [ -z $(which postgres) ] ; then
echo "Postgres not found, you may need to add /usr/lib/postgresql/<version>/bin to PATH."
exit 1
fi

postgres -D datadir/ -p 10432 -k `pwd`/datadir/ &
# Sleep for a bit and wait for the DB to start
sleep 1
17 changes: 17 additions & 0 deletions test/data/test_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--
-- Adapted from epgsql tests
--
create user squeel_test;

drop database if exists squeel_test_db;
create database squeel_test_db with encoding 'UTF8';
grant all on database squeel_test_db to squeel_test;

\c squeel_test_db;

create table test_table (
id integer primary key,
value text
);
insert into test_table (id, value) values (1, 'one');
insert into test_table (id, value) values (2, 'two');

0 comments on commit fcc4fd2

Please sign in to comment.