From 8c52d0eb284b0b095e62883eedfd815f9ecd0e6a Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Mon, 14 Aug 2023 08:24:53 +0100 Subject: [PATCH] Implement videos table. --- .../changelog/version/0-1-init-crdb.sql | 19 +++++++++++++++++++ .../changelog/version/0-1-init-pg.sql | 19 +++++++++++++++++++ .../resources/changelog/version/0-1-init.sql | 2 -- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/main/resources/changelog/version/0-1-init-crdb.sql b/src/main/resources/changelog/version/0-1-init-crdb.sql index ec15eae..0c5e646 100644 --- a/src/main/resources/changelog/version/0-1-init-crdb.sql +++ b/src/main/resources/changelog/version/0-1-init-crdb.sql @@ -1,3 +1,22 @@ CREATE INDEX IF NOT EXISTS users_session_id_idx ON users (session_id ASC) STORING (password, username); --rollback DROP INDEX IF EXISTS users_session_id_idx; + +CREATE TABLE IF NOT EXISTS videos ( + id VARCHAR(16) NOT NULL UNIQUE, + duration INT8 NULL, + thumbnail VARCHAR(400) NULL, + title VARCHAR(120) NULL, + uploaded INT8 NULL, + views INT8 NULL, + uploader_id VARCHAR(24) NOT NULL, + is_short BOOL NOT NULL DEFAULT false, + CONSTRAINT videos_pkey PRIMARY KEY (id ASC, uploader_id ASC) USING HASH, + CONSTRAINT fk_videos_channels_uploader_id FOREIGN KEY (uploader_id) REFERENCES channels(uploader_id), + INDEX videos_id_idx (id ASC), + INDEX video_uploaded_idx (uploaded ASC) USING HASH, + INDEX video_uploader_id_idx (uploader_id ASC) STORING (duration, thumbnail, title, uploaded, views, is_short), + UNIQUE INDEX videos_id_key (id ASC) STORING (duration, thumbnail, title, uploaded, views, is_short) +); + +--rollback DROP TABLE IF EXISTS videos; diff --git a/src/main/resources/changelog/version/0-1-init-pg.sql b/src/main/resources/changelog/version/0-1-init-pg.sql index 610e4c2..009add6 100644 --- a/src/main/resources/changelog/version/0-1-init-pg.sql +++ b/src/main/resources/changelog/version/0-1-init-pg.sql @@ -1,3 +1,22 @@ CREATE INDEX IF NOT EXISTS users_session_id_idx ON users (session_id ASC); --rollback DROP INDEX IF EXISTS users_session_id_idx; + +CREATE TABLE IF NOT EXISTS videos ( + id VARCHAR(16) NOT NULL UNIQUE, + duration INT8 NULL, + thumbnail VARCHAR(400) NULL, + title VARCHAR(120) NULL, + uploaded INT8 NULL, + views INT8 NULL, + uploader_id VARCHAR(24) NOT NULL, + is_short BOOL NOT NULL DEFAULT false, + CONSTRAINT videos_pkey PRIMARY KEY (id, uploader_id), + CONSTRAINT fk_videos_channels_uploader_id FOREIGN KEY (uploader_id) REFERENCES channels(uploader_id) +); + +CREATE UNIQUE INDEX IF NOT EXISTS videos_id_idx ON videos (id ASC); +CREATE INDEX IF NOT EXISTS video_uploaded_idx ON videos (uploaded ASC); +CREATE INDEX IF NOT EXISTS video_uploader_id_idx ON videos (uploader_id ASC); + +--rollback DROP TABLE IF EXISTS videos; diff --git a/src/main/resources/changelog/version/0-1-init.sql b/src/main/resources/changelog/version/0-1-init.sql index 6e6eb01..126e42f 100644 --- a/src/main/resources/changelog/version/0-1-init.sql +++ b/src/main/resources/changelog/version/0-1-init.sql @@ -10,7 +10,6 @@ DROP INDEX IF EXISTS users_id_idx; CREATE INDEX IF NOT EXISTS username_idx ON users (username ASC); ---rollback DROP INDEX IF EXISTS username_idx; --rollback DROP TABLE IF EXISTS users; CREATE TABLE IF NOT EXISTS channels ( @@ -23,5 +22,4 @@ CREATE TABLE IF NOT EXISTS channels ( CREATE INDEX IF NOT EXISTS channels_uploader_idx ON channels (uploader ASC); ---rollback DROP INDEX IF EXISTS channels_uploader_idx; --rollback DROP TABLE IF EXISTS channels;