Add more db shite

This commit is contained in:
2025-09-13 15:52:49 +03:00
parent 111bcedf2c
commit 7d88ac6db8
45 changed files with 971 additions and 5 deletions

View File

@@ -7,6 +7,7 @@ CREATE TABLE IF NOT EXISTS users (
username TEXT NOT NULL UNIQUE,
pw_hash TEXT NOT NULL,
pw_salt TEXT NOT NULL,
pfp_id BIGINT NOT NULL
pfp_id BIGINT NOT NULL,
rank_id BIGINT NOT NULL
);

View File

@@ -3,5 +3,6 @@
CREATE TABLE IF NOT EXISTS sessions (
user_id BIGINT NOT NULL,
session_key TEXT NOT NULL UNIQUE,
expires BIGINT NOT NULL
expires BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE
)

View File

@@ -0,0 +1 @@
DROP TABLE IF EXISTS ranks;

View File

@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS ranks (
id BIGSERIAL PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
created_at BIGINT NOT NULL,
modified_at BIGINT NOT NULL
);

View File

@@ -0,0 +1 @@
DROP TABLE IF EXISTS awards;

View File

@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS awards (
id BIGSERIAL PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
created_at BIGINT NOT NULL,
modified_at BIGINT NOT NULL
);

View File

@@ -0,0 +1 @@
DROP TABLE IF EXISTS trainings;

View File

@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS trainings (
id BIGSERIAL PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
created_at BIGINT NOT NULL,
modified_at BIGINT NOT NULL
);

View File

@@ -0,0 +1 @@
DROP TABLE IF EXISTS missions;

View File

@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS missions (
id BIGSERIAL PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
created_at BIGINT NOT NULL,
modified_at BIGINT NOT NULL
);

View File

@@ -0,0 +1 @@
DROP TABLE IF EXISTS qualifications;

View File

@@ -0,0 +1,7 @@
CREATE TABLE IF NOT EXISTS qualifications (
id BIGSERIAL PRIMARY KEY NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
created_at BIGINT NOT NULL,
modified_at BIGINT NOT NULL
);

View File

@@ -0,0 +1 @@
DROP TABLE IF EXISTS record_ranks;

View File

@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS records_ranks (
id BIGSERIAL PRIMARY KEY NOT NULL,
user_id BIGINT NOT NULL,
rank_id BIGINT NOT NULL,
author_id BIGINT NOT NULL,
created_at BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
CONSTRAINT fk_rank FOREIGN KEY (rank_id) REFERENCES ranks(id) ON DELETE CASCADE
);

View File

@@ -0,0 +1 @@
DROP TABLE IF EXISTS record_awards;

View File

@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS records_awards (
id BIGSERIAL PRIMARY KEY NOT NULL,
user_id BIGINT NOT NULL,
award_id BIGINT NOT NULL,
author_id BIGINT NOT NULL,
created_at BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
CONSTRAINT fk_award FOREIGN KEY (award_id) REFERENCES awards(id) ON DELETE CASCADE
);

View File

@@ -0,0 +1 @@
DROP TABLE IF EXISTS record_training;

View File

@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS records_trainings (
id BIGSERIAL PRIMARY KEY NOT NULL,
user_id BIGINT NOT NULL,
training_id BIGINT NOT NULL,
author_id BIGINT NOT NULL,
created_at BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
CONSTRAINT fk_training FOREIGN KEY (training_id) REFERENCES trainings(id) ON DELETE CASCADE
);

View File

@@ -0,0 +1 @@
DROP TABLE IF EXISTS record_qualifications;

View File

@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS records_qualifications (
id BIGSERIAL PRIMARY KEY NOT NULL,
user_id BIGINT NOT NULL,
qualification_id BIGINT NOT NULL,
author_id BIGINT NOT NULL,
created_at BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
CONSTRAINT fk_qualification FOREIGN KEY (qualification_id) REFERENCES qualifications(id) ON DELETE CASCADE
);

View File

@@ -0,0 +1 @@
DROP TABLE IF EXISTS records_missions;

View File

@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS records_missions (
id BIGSERIAL PRIMARY KEY NOT NULL,
user_id BIGINT NOT NULL,
mission_id BIGINT NOT NULL,
author_id BIGINT NOT NULL,
created_at BIGINT NOT NULL,
CONSTRAINT fk_user FOREIGN KEY(user_id) REFERENCES users(id) ON DELETE CASCADE,
CONSTRAINT fk_author FOREIGN KEY(author_id) REFERENCES users(id) ON DELETE SET NULL,
CONSTRAINT fk_mission FOREIGN KEY (mission_id) REFERENCES missions(id) ON DELETE CASCADE
);