Archived
Update sql scripts for creating and seeding db
This commit is contained in:
+43
-43
@@ -1,64 +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,
|
||||
-- Create Group table
|
||||
CREATE TABLE UserGroup (
|
||||
id UUID PRIMARY KEY DEFAULT uuid(),
|
||||
group_name VARCHAR UNIQUE 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,
|
||||
-- Create User Table
|
||||
CREATE TABLE User (
|
||||
id UUID PRIMARY KEY DEFAULT uuid(),
|
||||
name VARCHAR,
|
||||
username VARCHAR UNIQUE NOT NULL,
|
||||
email VARCHAR UNIQUE,
|
||||
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,
|
||||
hashed_password VARCHAR NOT NULL,
|
||||
is_active BOOLEAN DEFAULT true,
|
||||
is_admin BOOLEAN DEFAULT false,
|
||||
last_login TIMESTAMP,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
modified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (group_id) REFERENCES groups(id)
|
||||
modified_at timestamp DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (group_id) REFERENCES UserGroup(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,
|
||||
CREATE TABLE Contest (
|
||||
id UUID PRIMARY KEY DEFAULT uuid(),
|
||||
city_name VARCHAR NOT NULL,
|
||||
date DATE NOT NULL,
|
||||
round VARCHAR NOT NULL,
|
||||
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,
|
||||
-- Create Song Table with ARRAY type for tags
|
||||
CREATE TABLE Song (
|
||||
id UUID PRIMARY KEY DEFAULT uuid(),
|
||||
contest_id UUID NOT NULL,
|
||||
artist_name VARCHAR NOT NULL,
|
||||
song_title VARCHAR NOT NULL,
|
||||
country VARCHAR NOT NULL,
|
||||
lyrics TEXT,
|
||||
song_meaning TEXT,
|
||||
tags VARCHAR[],
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
modified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
modified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (contest_id) REFERENCES Contest(id)
|
||||
);
|
||||
|
||||
-- Create Reviews Table
|
||||
CREATE TABLE reviews (
|
||||
id UUID PRIMARY KEY,
|
||||
contest_id UUID,
|
||||
song_id UUID,
|
||||
reviewer_id UUID,
|
||||
-- Create Reviews Table with Score Constraints
|
||||
CREATE TABLE Reviews (
|
||||
id UUID PRIMARY KEY DEFAULT uuid(),
|
||||
song_id UUID NOT NULL,
|
||||
reviewer_id UUID NOT NULL,
|
||||
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,
|
||||
review_text TEXT,
|
||||
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)
|
||||
);
|
||||
|
||||
FOREIGN KEY (song_id) REFERENCES Song(id),
|
||||
FOREIGN KEY (reviewer_id) REFERENCES User(id)
|
||||
);
|
||||
Reference in New Issue
Block a user