diff --git a/postgres/Dockerfile b/postgres/Dockerfile index 6efcf752b..6456746d5 100644 --- a/postgres/Dockerfile +++ b/postgres/Dockerfile @@ -1,6 +1,6 @@ FROM mdillon/postgis -COPY initdb/* docker-entrypoint-initdb.d/ +COPY initdb.sql docker-entrypoint-initdb.d/ #COPY serviceAccountKey.json serviceAccountKey.json # Copy backup scripts and make them executable diff --git a/postgres/initdb/1-tables.sql b/postgres/initdb.sql similarity index 89% rename from postgres/initdb/1-tables.sql rename to postgres/initdb.sql index f0fbe1279..61a0f4c07 100644 --- a/postgres/initdb/1-tables.sql +++ b/postgres/initdb.sql @@ -105,10 +105,5 @@ CREATE TABLE IF NOT EXISTS results_temp ( start_time timestamp, end_time timestamp, result int, - PRIMARY KEY (project_id, group_id, task_id, user_id), - FOREIGN KEY (project_id) REFERENCES projects (project_id), - FOREIGN KEY (project_id, group_id) REFERENCES GROUPS (project_id, group_id), - FOREIGN KEY (project_id, group_id, task_id) REFERENCES tasks (project_id, group_id, task_id), - FOREIGN KEY (user_id) REFERENCES users (user_id) ); diff --git a/postgres/initdb/2-row-count.sql b/postgres/initdb/2-row-count.sql deleted file mode 100644 index 1888bb6c5..000000000 --- a/postgres/initdb/2-row-count.sql +++ /dev/null @@ -1,87 +0,0 @@ -/* http://www.varlena.com/GeneralBits/120.php */ -CREATE IF NOT EXISTS TABLE row_counts ( - relname text PRIMARY KEY, - reltuples numeric -); - -CREATE OR REPLACE FUNCTION count_trig () - RETURNS TRIGGER - AS $$ -DECLARE -BEGIN - IF TG_OP = 'INSERT' THEN - EXECUTE 'UPDATE row_counts set reltuples=reltuples +1 where relname = ''' || TG_RELNAME || ''''; - RETURN NEW; - ELSIF TG_OP = 'DELETE' THEN - EXECUTE 'UPDATE row_counts set reltuples=reltuples -1 where relname = ''' || TG_RELNAME || ''''; - RETURN OLD; - END IF; -END; -$$ -LANGUAGE 'plpgsql'; - - -/* add triggers to all tables in public schema */ -CREATE OR REPLACE FUNCTION add_count_trigs () - RETURNS void - AS $$ -DECLARE - rec RECORD; - q text; -BEGIN - FOR rec IN - SELECT - relname - FROM - pg_class r - JOIN pg_namespace n ON (relnamespace = n.oid) - WHERE - relkind = 'r' - AND n.nspname = 'public' LOOP - q := 'CREATE TRIGGER ' || rec.relname || '_count BEFORE INSERT OR DELETE ON '; - q := q || rec.relname || ' FOR EACH ROW EXECUTE PROCEDURE count_trig()'; - EXECUTE q; - END LOOP; - RETURN; -END; -$$ -LANGUAGE 'plpgsql'; - -CREATE OR REPLACE FUNCTION init_row_counts () - RETURNS void - AS $$ -DECLARE - rec RECORD; - crec RECORD; -BEGIN - FOR rec IN - SELECT - relname - FROM - pg_class r - JOIN pg_namespace n ON (relnamespace = n.oid) - WHERE - relkind = 'r' - AND n.nspname = 'public' LOOP - FOR crec IN EXECUTE 'SELECT count(*) as rows from ' || rec.relname LOOP - -- nothing here, move along - END LOOP; - INSERT INTO row_counts - VALUES (rec.relname, crec.rows); - END LOOP; - RETURN; -END; -$$ -LANGUAGE 'plpgsql'; - - -/* Stop server activity if possible. */ -VACUUM; - -BEGIN; -SELECT - add_count_trigs (); -SELECT - init_row_counts (); -COMMIT; -