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)
);
+47
View File
@@ -0,0 +1,47 @@
-- Insert test data into Groups Table
INSERT INTO groups (id, group_name, created_at, modified_at)
VALUES
('00000000-0000-0000-0000-000000000001', 'Admins', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('00000000-0000-0000-0000-000000000002', 'Judges Group A', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('00000000-0000-0000-0000-000000000003', 'Judges Group B', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
-- Insert test data into Users Table
INSERT INTO users (id, name, username, email, group_id, password, last_login_time, is_admin, is_active, created_at, modified_at)
VALUES
('11111111-1111-1111-1111-111111111111', 'Alice Admin', 'alice_admin', '[email protected]', '00000000-0000-0000-0000-000000000001', 'hashed_password_1', CURRENT_TIMESTAMP, TRUE, TRUE, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('22222222-2222-2222-2222-222222222222', 'Bob Judge', 'bob_judge', '[email protected]', '00000000-0000-0000-0000-000000000002', 'hashed_password_2', CURRENT_TIMESTAMP, FALSE, TRUE, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('33333333-3333-3333-3333-333333333333', 'Charlie Reviewer', 'charlie_reviewer', '[email protected]', '00000000-0000-0000-0000-000000000003', 'hashed_password_3', CURRENT_TIMESTAMP, FALSE, TRUE, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('44444444-4444-4444-4444-444444444444', 'Dana Inactive', 'dana_inactive', NULL, '00000000-0000-0000-0000-000000000003', 'hashed_password_4', NULL, FALSE, FALSE, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
-- Insert test data into Contests Table
INSERT INTO contests (id, city_name, date, round, is_active, created_at, modified_at)
VALUES
('55555555-5555-5555-5555-555555555555', 'Stockholm', '2023-05-14', 'Final', TRUE, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('66666666-6666-6666-6666-666666666666', 'Copenhagen', '2023-05-10', '1st semifinal', FALSE, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('77777777-7777-7777-7777-777777777777', 'Oslo', '2023-05-12', '2nd semifinal', FALSE, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
-- Insert test data into Songs Table
INSERT INTO songs (id, artist_name, song_title, country, lyrics, song_meaning, created_at, modified_at)
VALUES
('88888888-8888-8888-8888-888888888888', 'Artist A', 'Song of Hope', 'Sweden', NULL, 'This song represents resilience and hope.', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('99999999-9999-9999-9999-999999999999', 'Artist B', 'Ballad of Love', 'Denmark', 'Lyrics about love...', 'A romantic ballad.', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'Artist C', 'Dance with Me', 'Norway', NULL, 'A fun and energetic dance track.', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
-- Insert test data into Reviews Table
-- Each user reviews each song with dramatic variations in scores
INSERT INTO reviews (id, contest_id, song_id, reviewer_id, song_score, wardrobe_score, stage_show_score, review_text, created_at, modified_at)
VALUES
-- Reviews by Alice Admin (Group: Admins)
('11111111-0000-0000-0000-000000000001', '55555555-5555-5555-5555-555555555555', '88888888-8888-8888-8888-888888888888', '11111111-1111-1111-1111-111111111111', 95, 10, 80, 'Amazing song, but the wardrobe choice was absolutely terrible.', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('11111111-0000-0000-0000-000000000002', '55555555-5555-5555-5555-555555555555', '99999999-9999-9999-9999-999999999999', '11111111-1111-1111-1111-111111111111', 88, 95, 25, 'The song and wardrobe were great, but the stage show was far too chaotic.', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('11111111-0000-0000-0000-000000000003', '55555555-5555-5555-5555-555555555555', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '11111111-1111-1111-1111-111111111111', 40, 70, 15, 'I didnt connect with the song, and the show was awkward.', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
-- Reviews by Bob Judge (Group: Judges Group A)
('22222222-0000-0000-0000-000000000001', '55555555-5555-5555-5555-555555555555', '88888888-8888-8888-8888-888888888888', '22222222-2222-2222-2222-222222222222', 70, 65, 90, 'The stage show carried the performance, but the song was mediocre.', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('22222222-0000-0000-0000-000000000002', '55555555-5555-5555-5555-555555555555', '99999999-9999-9999-9999-999999999999', '22222222-2222-2222-2222-222222222222', 20, 80, 85, 'I really disliked the song, but the wardrobe and show were solid.', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('22222222-0000-0000-0000-000000000003', '55555555-5555-5555-5555-555555555555', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '22222222-2222-2222-2222-222222222222', 85, 30, 75, 'The wardrobe was distracting, but the song and show were decent.', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
-- Reviews by Charlie Reviewer (Group: Judges Group B)
('33333333-0000-0000-0000-000000000001', '55555555-5555-5555-5555-555555555555', '88888888-8888-8888-8888-888888888888', '33333333-3333-3333-3333-333333333333', 15, 90, 20, 'The wardrobe was stunning, but I absolutely hated the song.', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('33333333-0000-0000-0000-000000000002', '55555555-5555-5555-5555-555555555555', '99999999-9999-9999-9999-999999999999', '33333333-3333-3333-3333-333333333333', 65, 85, 10, 'Wardrobe and song were fine, but the show was offensive.', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP),
('33333333-0000-0000-0000-000000000003', '55555555-5555-5555-5555-555555555555', 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', '33333333-3333-3333-3333-333333333333', 92, 25, 88, 'The song was fantastic, but the wardrobe looked cheap.', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);