From 3515be836d0a4e429cdf438c66dbb8abd0c06b8b Mon Sep 17 00:00:00 2001 From: sudoer777 <78781902+sudoer777@users.noreply.github.com> Date: Thu, 25 Nov 2021 18:49:31 -0700 Subject: [PATCH] Add submitter_id column to init_database.sql script --- database/database.js | 1 - database/init_database.sql | 30 ++++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/database/database.js b/database/database.js index 1d5bc56..2f9277e 100644 --- a/database/database.js +++ b/database/database.js @@ -26,7 +26,6 @@ async function Initialize() { } - async function checkForDatabaseInitialization() { const query = `SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'scores'`; let result = await executeQuery(query); diff --git a/database/init_database.sql b/database/init_database.sql index ea8decf..c7de265 100644 --- a/database/init_database.sql +++ b/database/init_database.sql @@ -30,6 +30,18 @@ accounts: BEGIN; +CREATE SCHEMA IF NOT EXISTS accounts; + +CREATE TABLE IF NOT EXISTS accounts.users( + user_id BIGINT GENERATED ALWAYS AS IDENTITY, + email TEXT UNIQUE NOT NULL, + password TEXT NOT NULL, + admin BOOLEAN NOT NULL DEFAULT FALSE, + PRIMARY KEY(user_id) + ); + + + CREATE SCHEMA IF NOT EXISTS scores; @@ -78,7 +90,7 @@ CREATE TABLE IF NOT EXISTS scores.games( team2_id BIGINT, team1_score INTEGER, team2_score INTEGER, -/* submitter_id BIGINT,*/ + submitter_id BIGINT, updated_timestamp TIMESTAMP WITH TIME ZONE DEFAULT now(), PRIMARY KEY(game_id), CONSTRAINT fk_division @@ -92,20 +104,10 @@ CREATE TABLE IF NOT EXISTS scores.games( REFERENCES scores.teams(team_id), CONSTRAINT fk_team2 FOREIGN KEY(team2_id) - REFERENCES scores.teams(team_id) -/* CONSTRAINT fk_submitter + REFERENCES scores.teams(team_id), + CONSTRAINT fk_submitter FOREIGN KEY(submitter_id) - REFERENCES accounts.users(user_id)*/ - ); - - -CREATE SCHEMA IF NOT EXISTS accounts; - -CREATE TABLE IF NOT EXISTS accounts.users( - user_id BIGINT GENERATED ALWAYS AS IDENTITY, - email TEXT UNIQUE NOT NULL, - password TEXT NOT NULL, - admin BOOLEAN NOT NULL DEFAULT FALSE + REFERENCES accounts.users(user_id) ); COMMIT; \ No newline at end of file