Change sql init script syntax

This commit is contained in:
Esa Kataja
2025-02-28 12:29:35 +02:00
parent e1a941687b
commit 24946ff81a
+11 -11
View File
@@ -1,5 +1,5 @@
-- Create Group table
CREATE TABLE UserGroup (
CREATE TABLE usergroups (
id UUID PRIMARY KEY DEFAULT uuid(),
group_name VARCHAR UNIQUE NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
@@ -7,23 +7,23 @@ CREATE TABLE UserGroup (
);
-- Create User Table
CREATE TABLE User (
CREATE TABLE users (
id UUID PRIMARY KEY DEFAULT uuid(),
name VARCHAR,
username VARCHAR UNIQUE NOT NULL,
email VARCHAR UNIQUE,
group_id UUID,
hashed_password VARCHAR NOT NULL,
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 UserGroup(id)
modified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (group_id) REFERENCES usergroups(id)
);
-- Create Contest Table
CREATE TABLE Contest (
CREATE TABLE contests (
id UUID PRIMARY KEY DEFAULT uuid(),
city_name VARCHAR NOT NULL,
date DATE NOT NULL,
@@ -34,7 +34,7 @@ CREATE TABLE Contest (
);
-- Create Song Table with ARRAY type for tags
CREATE TABLE Song (
CREATE TABLE songs (
id UUID PRIMARY KEY DEFAULT uuid(),
contest_id UUID NOT NULL,
artist_name VARCHAR NOT NULL,
@@ -45,11 +45,11 @@ CREATE TABLE Song (
tags VARCHAR[],
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (contest_id) REFERENCES Contest(id)
FOREIGN KEY (contest_id) REFERENCES contests(id)
);
-- Create Reviews Table with Score Constraints
CREATE TABLE Reviews (
CREATE TABLE reviews (
id UUID PRIMARY KEY DEFAULT uuid(),
song_id UUID NOT NULL,
reviewer_id UUID NOT NULL,
@@ -59,6 +59,6 @@ CREATE TABLE Reviews (
review_text TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
modified_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (song_id) REFERENCES Song(id),
FOREIGN KEY (reviewer_id) REFERENCES User(id)
FOREIGN KEY (song_id) REFERENCES songs(id),
FOREIGN KEY (reviewer_id) REFERENCES users(id)
);