ADD Database schema and seed data

This commit is contained in:
Esa Kataja
2025-02-09 18:59:40 +02:00
parent fab88745e9
commit 7120990689
2 changed files with 111 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
-- Create Groups Table. Users are split into groups. Users review songs in their respective group.
CREATE TABLE groups (
id UUID PRIMARY KEY,
group_name STRING NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Create Users Table (Updated with Foreign Key for Group)
CREATE TABLE users (
id UUID PRIMARY KEY,
name STRING DEFAULT NULL,
username STRING UNIQUE NOT NULL,
email STRING UNIQUE DEFAULT NULL,
group_id UUID,
password STRING NOT NULL, -- Hashed password
last_login_time TIMESTAMP DEFAULT NULL,
is_admin BOOLEAN DEFAULT FALSE,
is_active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (group_id) REFERENCES groups(id)
);
-- Create Contest Table
CREATE TABLE contests (
id UUID PRIMARY KEY,
city_name STRING NOT NULL, -- Name of the city where the contest is held.
date DATE NOT NULL, -- Date when the contest is to be held.
round STRING NOT NULL, -- Can be one of "1st semifinal", "2nd semifinal", "final"
is_active BOOLEAN DEFAULT FALSE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Create Song Table
CREATE TABLE songs (
id UUID PRIMARY KEY,
artist_name STRING NOT NULL,
song_title STRING NOT NULL,
country STRING NOT NULL,
lyrics TEXT DEFAULT NULL,
song_meaning TEXT DEFAULT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
-- Create Reviews Table
CREATE TABLE reviews (
id UUID PRIMARY KEY,
contest_id UUID,
song_id UUID,
reviewer_id UUID,
song_score INTEGER CHECK (song_score BETWEEN 1 AND 100),
wardrobe_score INTEGER CHECK (wardrobe_score BETWEEN 1 AND 100),
stage_show_score INTEGER CHECK (stage_show_score BETWEEN 1 AND 100),
review_text TEXT DEFAULT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (contest_id) REFERENCES contests(id),
FOREIGN KEY (song_id) REFERENCES songs(id),
FOREIGN KEY (reviewer_id) REFERENCES users(id)
);