From dbb795b2c851e23d7af2de3983138dcd66d6104c Mon Sep 17 00:00:00 2001
From: ilotterytea <iltsu@alright.party>
Date: Sat, 14 Dec 2024 00:10:40 +0500
Subject: fix: sql fixes

---
 migrations/2024-05-11T02-53-05_init/up.sql | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

(limited to 'migrations/2024-05-11T02-53-05_init/up.sql')

diff --git a/migrations/2024-05-11T02-53-05_init/up.sql b/migrations/2024-05-11T02-53-05_init/up.sql
index c50562f..1a23ff9 100644
--- a/migrations/2024-05-11T02-53-05_init/up.sql
+++ b/migrations/2024-05-11T02-53-05_init/up.sql
@@ -16,15 +16,15 @@ CREATE TABLE IF NOT EXISTS "users"  (
 );
 
 CREATE TABLE IF NOT EXISTS "channel_preferences" (
-  "channel_id" INTEGER NOT NULL UNIQUE PRIMARY KEY REFERENCES "channels"("id"),
+  "channel_id" INTEGER NOT NULL UNIQUE PRIMARY KEY REFERENCES "channels"("id") ON DELETE CASCADE,
   "prefix" VARCHAR,
   "locale" VARCHAR
 );
 
 CREATE TABLE IF NOT EXISTS "user_rights" (
   "id" SERIAL NOT NULL UNIQUE PRIMARY KEY,
-  "user_id" INTEGER NOT NULL REFERENCES "users"("id"),
-  "channel_id" INTEGER NOT NULL REFERENCES "channels"("id"),
+  "user_id" INTEGER NOT NULL REFERENCES "users"("id") ON DELETE CASCADE,
+  "channel_id" INTEGER NOT NULL REFERENCES "channels"("id") ON DELETE CASCADE,
   "level" INTEGER NOT NULL DEFAULT 1,
 
   CONSTRAINT "unique_user_channel" UNIQUE ("user_id", "channel_id")
@@ -32,8 +32,8 @@ CREATE TABLE IF NOT EXISTS "user_rights" (
 
 CREATE TABLE IF NOT EXISTS "actions" (
   "id" SERIAL NOT NULL UNIQUE PRIMARY KEY,
-  "user_id" INTEGER NOT NULL REFERENCES "users"("id"),
-  "channel_id" INTEGER NOT NULL REFERENCES "channels"("id"),
+  "user_id" INTEGER NOT NULL REFERENCES "users"("id") ON DELETE CASCADE,
+  "channel_id" INTEGER NOT NULL REFERENCES "channels"("id") ON DELETE CASCADE,
   "command" VARCHAR NOT NULL,
   "arguments" VARCHAR,
   "full_message" VARCHAR NOT NULL,
@@ -42,7 +42,7 @@ CREATE TABLE IF NOT EXISTS "actions" (
 
 CREATE TABLE IF NOT EXISTS "events" (
   "id" SERIAL NOT NULL UNIQUE PRIMARY KEY,
-  "channel_id" INTEGER NOT NULL REFERENCES "channels"("id"),
+  "channel_id" INTEGER NOT NULL REFERENCES "channels"("id") ON DELETE CASCADE,
   "target_alias_id" INTEGER,
   "custom_alias_id" VARCHAR,
   "event_type" INTEGER NOT NULL,
@@ -55,20 +55,20 @@ CREATE TABLE IF NOT EXISTS "events" (
 
 CREATE TABLE IF NOT EXISTS "event_subscriptions" (
   "id" SERIAL NOT NULL UNIQUE PRIMARY KEY,
-  "event_id" INTEGER NOT NULL REFERENCES "events"("id"),
-  "user_id" INTEGER NOT NULL REFERENCES "users"("id")
+  "event_id" INTEGER NOT NULL REFERENCES "events"("id") ON DELETE CASCADE,
+  "user_id" INTEGER NOT NULL REFERENCES "users"("id") ON DELETE CASCADE
 );
 
 CREATE TABLE IF NOT EXISTS "custom_commands" (
   "id" SERIAL NOT NULL UNIQUE PRIMARY KEY,
-  "channel_id" INTEGER NOT NULL REFERENCES "channels"("id"),
+  "channel_id" INTEGER NOT NULL REFERENCES "channels"("id") ON DELETE CASCADE,
   "name" VARCHAR NOT NULL,
   "message" VARCHAR NOT NULL
 );
 
 CREATE TABLE IF NOT EXISTS "timers" (
   "id" SERIAL NOT NULL UNIQUE PRIMARY KEY,
-  "channel_id" INTEGER NOT NULL REFERENCES "channels"("id"),
+  "channel_id" INTEGER NOT NULL REFERENCES "channels"("id") ON DELETE CASCADE,
   "name" VARCHAR NOT NULL,
   "message" VARCHAR NOT NULL,
   "interval_sec" INTEGER NOT NULL,
-- 
cgit v1.2.3

