Archived
65 lines
2.2 KiB
SQL
65 lines
2.2 KiB
SQL
-- 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)
|
|
);
|
|
|