From ecbf139a9b314adb4ead3f67548df79d7e7ef39c Mon Sep 17 00:00:00 2001 From: soxx Date: Tue, 28 Jan 2025 13:39:26 +0100 Subject: [PATCH] feat(database): add ON DELETE CASCADE constraints --- pkg/database/migrations/001_inital_database.sql | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/pkg/database/migrations/001_inital_database.sql b/pkg/database/migrations/001_inital_database.sql index 3812a71..cbacc15 100644 --- a/pkg/database/migrations/001_inital_database.sql +++ b/pkg/database/migrations/001_inital_database.sql @@ -91,7 +91,6 @@ CREATE TABLE "Tag" deleted_at TIMESTAMP WITH TIME ZONE NULL ); - CREATE TABLE "TagAlias" ( id SERIAL PRIMARY KEY, @@ -114,7 +113,7 @@ CREATE TABLE "UserSource" created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, deleted_at TIMESTAMP WITH TIME ZONE NULL NULL, - user_id CHAR(25) REFERENCES "User" (id), + user_id CHAR(25) REFERENCES "User" (id) ON DELETE CASCADE, source_id TEXT REFERENCES "Source" (id), scrape_time_interval TEXT, account_username TEXT, @@ -131,9 +130,9 @@ CREATE TABLE "UserFavorites" created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP, deleted_at TIMESTAMP WITH TIME ZONE NULL NULL, - user_id TEXT REFERENCES "User" (id), + user_id TEXT REFERENCES "User" (id) ON DELETE CASCADE, post_id CHAR(25) REFERENCES "Post" (id), - user_source_id CHAR(25) REFERENCES "UserSource" (id) + user_source_id CHAR(25) REFERENCES "UserSource" (id) ON DELETE CASCADE ); CREATE INDEX idx_user_post_deleted ON "UserFavorites"(user_id, deleted_at); @@ -146,7 +145,6 @@ CREATE TABLE "post_tags" PRIMARY KEY (post_id, tag_id) ); - CREATE TABLE "Pool" ( id CHAR(25) PRIMARY KEY, @@ -159,7 +157,7 @@ CREATE TABLE "Pool" CREATE TABLE "PoolPost" ( - pool_id CHAR(25) REFERENCES "Pool" (id), + pool_id CHAR(25) REFERENCES "Pool" (id) ON DELETE CASCADE, post_id CHAR(25) REFERENCES "Post" (id), order_position INT NOT NULL DEFAULT 0, PRIMARY KEY (pool_id, post_id) @@ -167,7 +165,7 @@ CREATE TABLE "PoolPost" CREATE TABLE "PoolReference" ( - pool_id CHAR(25) REFERENCES "Pool" (id), + pool_id CHAR(25) REFERENCES "Pool" (id) ON DELETE CASCADE, source_id CHAR(25) REFERENCES "Source" (id), url TEXT NOT NULL, PRIMARY KEY (pool_id, source_id, url) @@ -197,4 +195,4 @@ CREATE TABLE "PostReport" audit_description TEXT NOT NULL, report_type ReportType NOT NULL, report_state ReportState NOT NULL -); \ No newline at end of file +);