From 3bcf74c47d1597ba650dc5a55868f83f5f547ad7 Mon Sep 17 00:00:00 2001
From: Anhgelus Morhtuuzh <william@herges.fr>
Date: Sun, 8 Mar 2026 14:12:03 +0100
Subject: feat(user): leave gorm

---
 migrations/000-leave-gorm.sql | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

(limited to 'migrations/000-leave-gorm.sql')

diff --git a/migrations/000-leave-gorm.sql b/migrations/000-leave-gorm.sql
index f80555a..360e2e3 100644
--- a/migrations/000-leave-gorm.sql
+++ b/migrations/000-leave-gorm.sql
@@ -9,13 +9,14 @@ CREATE TABLE IF NOT EXISTS guilds (
 );
 
 CREATE TABLE IF NOT EXISTS copaings (
-    id snowflake PRIMARY KEY,
-    guild_id snowflake REFERENCES guilds(id) NOT NULL
+    id snowflake UNIQUE,
+    guild_id snowflake REFERENCES guilds(id) ON DELETE CASCADE,
+    PRIMARY KEY(id, guild_id)
 );
 
 CREATE TABLE IF NOT EXISTS copaing_xps (
-    copaing_id snowflake REFERENCES copaings(id) NOT NULL,
-    guild_id snowflake REFERENCES copaings(id) NOT NULL,
+    copaing_id snowflake REFERENCES copaings(id) ON DELETE CASCADE,
+    guild_id snowflake REFERENCES copaings(id) ON DELETE CASCADE,
     xp uint DEFAULT 0,
     created_at TIMESTAMP DEFAULT now(),
     PRIMARY KEY(copaing_id, guild_id, created_at)
@@ -24,7 +25,7 @@ CREATE TABLE IF NOT EXISTS copaing_xps (
 CREATE TABLE IF NOT EXISTS xp_roles (
     xp uint,
     role snowflake,
-    guild_id snowflake REFERENCES guilds(id),
+    guild_id snowflake REFERENCES guilds(id) ON DELETE CASCADE,
     PRIMARY KEY(xp, role, guild_id)
 );
 
@@ -32,13 +33,13 @@ CREATE TABLE IF NOT EXISTS role_react_messages (
     id SERIAL PRIMARY KEY,
     message_id snowflake,
     channel_id snowflake,
-    guild_id snowflake REFERENCES guilds(id),
+    guild_id snowflake REFERENCES guilds(id) ON DELETE CASCADE,
     note TEXT
 );
 
 CREATE TABLE IF NOT EXISTS role_reacts (
     role snowflake,
-    message_id INTEGER REFERENCES role_react_messages(id),
+    message_id INTEGER REFERENCES role_react_messages(id) ON DELETE CASCADE,
     reaction TEXT,
     PRIMARY KEY(role, message_id, reaction)
 );
-- 
cgit v1.2.3

