From b0a97faf4f60b74fe32edc982e6f938b244c088d Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Mon, 14 Aug 2023 08:32:26 +0100 Subject: [PATCH] Add users_subscribed table. --- .../resources/changelog/version/0-1-init-crdb.sql | 11 +++++++++++ src/main/resources/changelog/version/0-1-init-pg.sql | 12 ++++++++++++ 2 files changed, 23 insertions(+) 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 0c5e646..395cf02 100644 --- a/src/main/resources/changelog/version/0-1-init-crdb.sql +++ b/src/main/resources/changelog/version/0-1-init-crdb.sql @@ -20,3 +20,14 @@ CREATE TABLE IF NOT EXISTS videos ( ); --rollback DROP TABLE IF EXISTS videos; + +CREATE TABLE IF NOT EXISTS users_subscribed ( + subscriber INT8 NOT NULL, + channel VARCHAR(24) NOT NULL, + CONSTRAINT users_subscribed_pkey PRIMARY KEY (subscriber ASC, channel ASC) USING HASH, + CONSTRAINT fk_subscriber_users FOREIGN KEY (subscriber) REFERENCES users(id), + INDEX users_subscribed_subscriber_idx (subscriber ASC), + INDEX users_subscribed_channel_idx (channel ASC) +); + +--rollback DROP TABLE IF EXISTS users_subscribed; 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 009add6..8362d82 100644 --- a/src/main/resources/changelog/version/0-1-init-pg.sql +++ b/src/main/resources/changelog/version/0-1-init-pg.sql @@ -20,3 +20,15 @@ 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; + +CREATE TABLE IF NOT EXISTS users_subscribed ( + subscriber INT8 NOT NULL, + channel VARCHAR(24) NOT NULL, + CONSTRAINT users_subscribed_pkey PRIMARY KEY (subscriber, channel), + CONSTRAINT fk_subscriber_users FOREIGN KEY (subscriber) REFERENCES users(id) +); + +CREATE INDEX IF NOT EXISTS users_subscribed_subscriber_idx ON users_subscribed (subscriber ASC); +CREATE INDEX IF NOT EXISTS users_subscribed_channel_idx ON users_subscribed (channel ASC); + +--rollback DROP TABLE IF EXISTS users_subscribed;