2021-11-18 21:13:03 +00:00
|
|
|
/* SCORE TRACKER DATABASE LAYOUT
|
|
|
|
|
|
|
|
scores:
|
|
|
|
|
|
|
|
sports:
|
2021-11-19 18:42:08 +00:00
|
|
|
*sport_id* | sport_name | currently_active
|
2021-11-18 21:13:03 +00:00
|
|
|
|
|
|
|
divisions:
|
2021-11-19 18:42:08 +00:00
|
|
|
*division_id* | division_name | gender | *sport_id* | currently_active
|
2021-11-18 21:13:03 +00:00
|
|
|
|
|
|
|
teams:
|
2021-11-19 18:42:08 +00:00
|
|
|
*team_id* | team_name | ~sport_id~ | currently_active
|
2021-11-18 21:13:03 +00:00
|
|
|
|
|
|
|
seasons:
|
|
|
|
*season_id* | school_year
|
|
|
|
|
|
|
|
games:
|
2021-11-19 18:42:08 +00:00
|
|
|
*game_id* | ~division_id~ | ~season_id~ | game_date | ~team1_id~ | ~team2_id~ | team1_score | team2_score | ~submitter_id~ | updated_timestamp
|
2021-11-18 21:13:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
accounts:
|
|
|
|
|
|
|
|
users:
|
2021-11-24 22:53:42 +00:00
|
|
|
*user_id* | email | password | admin
|
2021-11-18 21:13:03 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
BEGIN;
|
|
|
|
|
|
|
|
|
2021-11-26 01:49:31 +00:00
|
|
|
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)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-11-18 21:13:03 +00:00
|
|
|
CREATE SCHEMA IF NOT EXISTS scores;
|
|
|
|
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS scores.sports(
|
|
|
|
sport_id BIGINT GENERATED ALWAYS AS IDENTITY,
|
|
|
|
sport_name TEXT UNIQUE NOT NULL,
|
|
|
|
currently_active BOOLEAN DEFAULT TRUE,
|
|
|
|
PRIMARY KEY(sport_id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS scores.divisions(
|
|
|
|
division_id BIGINT GENERATED ALWAYS AS IDENTITY,
|
|
|
|
division_name TEXT NOT NULL,
|
|
|
|
gender VARCHAR(1) CHECK (gender IN ( 'F', 'M' ) ),
|
|
|
|
sport_id BIGINT,
|
|
|
|
currently_active BOOLEAN DEFAULT TRUE,
|
|
|
|
PRIMARY KEY(division_id),
|
|
|
|
CONSTRAINT fk_sport
|
|
|
|
FOREIGN KEY(sport_id)
|
|
|
|
REFERENCES scores.sports(sport_id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS scores.teams(
|
|
|
|
team_id BIGINT GENERATED ALWAYS AS IDENTITY,
|
|
|
|
team_name TEXT NOT NULL,
|
|
|
|
sport_id BIGINT,
|
|
|
|
currently_active BOOLEAN DEFAULT TRUE,
|
|
|
|
PRIMARY KEY(team_id),
|
|
|
|
CONSTRAINT fk_sport
|
|
|
|
FOREIGN KEY(sport_id)
|
|
|
|
REFERENCES scores.sports(sport_id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS scores.seasons(
|
|
|
|
season_id BIGINT GENERATED ALWAYS AS IDENTITY,
|
|
|
|
school_year INTEGER NOT NULL,
|
|
|
|
PRIMARY KEY(season_id)
|
|
|
|
);
|
|
|
|
|
|
|
|
CREATE TABLE IF NOT EXISTS scores.games(
|
|
|
|
game_id BIGINT GENERATED ALWAYS AS IDENTITY,
|
|
|
|
division_id BIGINT,
|
|
|
|
season_id BIGINT,
|
|
|
|
game_date DATE,
|
|
|
|
team1_id BIGINT,
|
|
|
|
team2_id BIGINT,
|
|
|
|
team1_score INTEGER,
|
|
|
|
team2_score INTEGER,
|
2021-11-26 01:49:31 +00:00
|
|
|
submitter_id BIGINT,
|
2021-11-18 21:13:03 +00:00
|
|
|
updated_timestamp TIMESTAMP WITH TIME ZONE DEFAULT now(),
|
|
|
|
PRIMARY KEY(game_id),
|
|
|
|
CONSTRAINT fk_division
|
|
|
|
FOREIGN KEY(division_id)
|
|
|
|
REFERENCES scores.divisions(division_id),
|
|
|
|
CONSTRAINT fk_season
|
|
|
|
FOREIGN KEY(season_id)
|
|
|
|
REFERENCES scores.seasons(season_id),
|
|
|
|
CONSTRAINT fk_team1
|
|
|
|
FOREIGN KEY(team1_id)
|
|
|
|
REFERENCES scores.teams(team_id),
|
|
|
|
CONSTRAINT fk_team2
|
|
|
|
FOREIGN KEY(team2_id)
|
2021-11-26 01:49:31 +00:00
|
|
|
REFERENCES scores.teams(team_id),
|
|
|
|
CONSTRAINT fk_submitter
|
2021-11-18 21:13:03 +00:00
|
|
|
FOREIGN KEY(submitter_id)
|
2021-11-26 01:49:31 +00:00
|
|
|
REFERENCES accounts.users(user_id)
|
2021-11-24 22:53:42 +00:00
|
|
|
);
|
|
|
|
|
2021-11-18 21:13:03 +00:00
|
|
|
COMMIT;
|