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