Add song listing endpoints
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
-- DuckDB SQL Schema Definition for Eurovision 25 Homereview Backend
|
||||
-- Generated from schema documentation.
|
||||
-- Target Database: DuckDB
|
||||
-- Incorporates Sequences for Auto-Incrementing Primary Keys.
|
||||
-- Note: Timestamps default to creation time; application logic should handle 'updated_at' updates.
|
||||
|
||||
-- Drop objects in reverse order of dependency and existence check
|
||||
DROP TABLE IF EXISTS Review;
|
||||
DROP TABLE IF EXISTS Song;
|
||||
DROP TABLE IF EXISTS "User"; -- Quoted because USER is a reserved keyword
|
||||
DROP TABLE IF EXISTS "Group"; -- Quoted because GROUP is a reserved keyword
|
||||
DROP TABLE IF EXISTS CountryCodes;
|
||||
|
||||
DROP SEQUENCE IF EXISTS group_id_seq;
|
||||
DROP SEQUENCE IF EXISTS user_id_seq;
|
||||
DROP SEQUENCE IF EXISTS song_id_seq;
|
||||
DROP SEQUENCE IF EXISTS review_id_seq;
|
||||
|
||||
-- =============================================================================
|
||||
-- Sequences for Primary Keys
|
||||
-- =============================================================================
|
||||
CREATE SEQUENCE group_id_seq START 1;
|
||||
CREATE SEQUENCE user_id_seq START 1;
|
||||
CREATE SEQUENCE song_id_seq START 1;
|
||||
CREATE SEQUENCE review_id_seq START 1;
|
||||
|
||||
-- =============================================================================
|
||||
-- Table: Group
|
||||
-- Stores information about the different households or groups participating.
|
||||
-- =============================================================================
|
||||
CREATE TABLE "Group" (
|
||||
id INTEGER PRIMARY KEY DEFAULT nextval('group_id_seq'), -- Use sequence for auto-increment
|
||||
name VARCHAR UNIQUE NOT NULL, -- The name of the household/group
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- Timestamp when the group was created
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP -- Timestamp when the group was last updated
|
||||
);
|
||||
|
||||
-- =============================================================================
|
||||
-- Table: User
|
||||
-- Stores information about individual users (players and admins).
|
||||
-- =============================================================================
|
||||
CREATE TABLE "User" (
|
||||
id INTEGER PRIMARY KEY DEFAULT nextval('user_id_seq'), -- Use sequence for auto-increment
|
||||
username VARCHAR UNIQUE NOT NULL, -- The user's login name
|
||||
hashed_password VARCHAR NOT NULL, -- The securely hashed password
|
||||
email VARCHAR UNIQUE, -- User's email address (nullable)
|
||||
group_id INTEGER NOT NULL, -- Foreign Key -> Group.id
|
||||
avatar_id INTEGER DEFAULT 0 NOT NULL, -- Identifier for the user's avatar
|
||||
is_active BOOLEAN DEFAULT TRUE NOT NULL, -- Flag indicating if the user account is active
|
||||
is_admin BOOLEAN DEFAULT FALSE NOT NULL, -- Flag indicating if the user has admin privileges
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- Timestamp when the user was created
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- Timestamp when the user was last updated
|
||||
|
||||
FOREIGN KEY (group_id) REFERENCES "Group"(id) -- Link to the Group table
|
||||
);
|
||||
|
||||
-- =============================================================================
|
||||
-- Table: Song
|
||||
-- Stores information about each participating song in the contest.
|
||||
-- =============================================================================
|
||||
CREATE TABLE Song (
|
||||
id INTEGER PRIMARY KEY DEFAULT nextval('song_id_seq'), -- Use sequence for auto-increment
|
||||
year INTEGER NOT NULL, -- The year of the Eurovision contest
|
||||
country VARCHAR NOT NULL, -- The participating country name
|
||||
artist VARCHAR NOT NULL, -- The name of the performing artist(s)
|
||||
title VARCHAR NOT NULL, -- The title of the song
|
||||
running_order INTEGER NOT NULL, -- Official order in the show (nullable)
|
||||
lyrics_url VARCHAR, -- URL to the original lyrics (nullable)
|
||||
artist_url VARCHAR, -- URL to the artist's page (nullable)
|
||||
flag_url VARCHAR, -- URL to the country flag (nullable)
|
||||
lyrics_original VARCHAR, -- Original lyrics (nullable)
|
||||
lyrics_translation_fi VARCHAR, -- Finnish translation (nullable)
|
||||
tags VARCHAR[], -- Comma-separated tags (nullable)
|
||||
confidence FLOAT NOT NULL DEFAULT 0.0, -- Confidence level of the translation (nullable)
|
||||
language VARCHAR NOT NULL, -- Language of the song (nullable)
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- Timestamp when the song entry was created
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP -- Timestamp when the song entry was last updated
|
||||
);
|
||||
|
||||
-- Add index for faster lookups by year as specified in documentation
|
||||
CREATE INDEX idx_song_year ON Song (year);
|
||||
|
||||
-- =============================================================================
|
||||
-- Table: Review
|
||||
-- Stores the scores and comments submitted by a user for a specific song.
|
||||
-- =============================================================================
|
||||
CREATE TABLE Review (
|
||||
id INTEGER PRIMARY KEY DEFAULT nextval('review_id_seq'), -- Use sequence for auto-increment
|
||||
user_id INTEGER NOT NULL, -- Foreign Key -> User.id
|
||||
song_id INTEGER NOT NULL, -- Foreign Key -> Song.id
|
||||
score_song INTEGER NOT NULL, -- Score (1-100) for song quality
|
||||
score_show INTEGER NOT NULL, -- Score (1-100) for the stage show
|
||||
score_wardrobe INTEGER NOT NULL, -- Score (1-100) for wardrobe/costumes
|
||||
text_review VARCHAR, -- Optional textual comments (nullable)
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- Timestamp when the review was created
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- Timestamp when the review was last modified
|
||||
|
||||
FOREIGN KEY (user_id) REFERENCES "User"(id), -- Link to the User table
|
||||
FOREIGN KEY (song_id) REFERENCES Song(id), -- Link to the Song table
|
||||
|
||||
-- Ensure scores are within the valid range (1-100)
|
||||
CHECK (score_song >= 1 AND score_song <= 100),
|
||||
CHECK (score_show >= 1 AND score_show <= 100),
|
||||
CHECK (score_wardrobe >= 1 AND score_wardrobe <= 100),
|
||||
|
||||
-- Ensure each user can only submit one review per song
|
||||
UNIQUE (user_id, song_id)
|
||||
);
|
||||
|
||||
CREATE TABLE CountryCodes (
|
||||
code VARCHAR PRIMARY KEY,
|
||||
name_en VARCHAR NOT NULL,
|
||||
name_fi VARCHAR NOT NULL
|
||||
);
|
||||
-- =============================================================================
|
||||
-- Views (Optional - Not Created Here Based on Documentation Decision)
|
||||
-- =============================================================================
|
||||
-- The documentation suggests performing result aggregations in the application
|
||||
-- layer. No CREATE VIEW statements are included.
|
||||
-- =============================================================================
|
||||
|
||||
-- End of Schema Definition
|
||||
Reference in New Issue
Block a user