diff --git a/initpg.sh b/initpg.sh new file mode 100755 index 0000000..4b2a2af --- /dev/null +++ b/initpg.sh @@ -0,0 +1,7 @@ +source ./pg.env + +pg_ctl init + +mkdir -p "$PGDATA/sockets" +echo "unix_socket_directories = 'sockets'" >> "$PGDATA/postgresql.conf" +echo "listen_addresses = ''" >> "$PGDATA/postgresql.conf" diff --git a/pg.env b/pg.env new file mode 100644 index 0000000..3b9f7f7 --- /dev/null +++ b/pg.env @@ -0,0 +1,4 @@ +export PGDATA="$PWD/pgdata" +export PGHOST="$PGDATA/sockets" +export PGDATABASE="postgres" +export PGUSER="$USER" diff --git a/phrasedb.sql b/phrasedb.sql index 8afa02e..03cdd5b 100644 --- a/phrasedb.sql +++ b/phrasedb.sql @@ -1,12 +1,25 @@ -CREATE TABLE IF NOT EXISTS phrases ( - id INTEGER PRIMARY KEY, - sourceid INTEGER, - phrase TEXT UNIQUE, +DROP TABLE phrases; +DROP TABLE sources; +DROP TABLE CORPORA; - FOREIGN KEY (sourceid) REFERENCES sources(sourceid) +CREATE TABLE IF NOT EXISTS corpora ( + id char(7) PRIMARY KEY, + name TEXT UNIQUE ); CREATE TABLE IF NOT EXISTS sources ( - id INTEGER PRIMARY KEY, - name TEXT UNIQUE + id char(7) PRIMARY KEY, + corpusid char(7) NOT NULL, + name TEXT UNIQUE, + + FOREIGN KEY (corpusid) REFERENCES corpora(id) ON DELETE CASCADE ); + +CREATE TABLE IF NOT EXISTS phrases ( + id SERIAL PRIMARY KEY, + sourceid char(7) NOT NULL, + phrase TEXT, + + FOREIGN KEY (sourceid) REFERENCES sources(id) ON DELETE CASCADE +); + diff --git a/startpg.sh b/startpg.sh new file mode 100755 index 0000000..6f6dd8b --- /dev/null +++ b/startpg.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +source ./pg.env + +pg_ctl start