From ef056edf92b678265a4666e1f9405e3b0ce66a42 Mon Sep 17 00:00:00 2001
From: Nathan Perry <np@nathanperry.dev>
Date: Fri, 16 Aug 2024 21:14:30 -0400
Subject: repo: overhaul for multitenancy

---
 migrations/2024-08-16-111659_multitenant/up.sql | 35 +++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 migrations/2024-08-16-111659_multitenant/up.sql

(limited to 'migrations/2024-08-16-111659_multitenant/up.sql')

diff --git a/migrations/2024-08-16-111659_multitenant/up.sql b/migrations/2024-08-16-111659_multitenant/up.sql
new file mode 100644
index 0000000..8bda619
--- /dev/null
+++ b/migrations/2024-08-16-111659_multitenant/up.sql
@@ -0,0 +1,35 @@
+ALTER TABLE memes
+    DROP CONSTRAINT IF EXISTS text_memes_title_key,
+    DROP CONSTRAINT IF EXISTS text_memes_content_image_id_audio_id_key,
+    DROP CONSTRAINT IF EXISTS text_memes_metadata_id_key,
+    DROP CONSTRAINT IF EXISTS memes_guild_title_key,
+    DROP CONSTRAINT IF EXISTS memes_guild_content_image_id_audio_id_key,
+    DROP CONSTRAINT IF EXISTS memes_guild_metadata_id_key
+;
+
+DROP INDEX IF EXISTS text_memes_title_key, text_memes_content_image_id_audio_id_key, text_memes_metadata_id_key;
+
+ALTER TABLE memes
+    ADD COLUMN IF NOT EXISTS guild BIGINT;
+
+ALTER TABLE MEMES
+    ALTER COLUMN guild TYPE BIGINT,
+    ADD CONSTRAINT memes_guild_title_key UNIQUE (guild, title),
+    ADD CONSTRAINT memes_guild_content_image_id_audio_id_key UNIQUE (guild, content, image_id, audio_id),
+    ADD CONSTRAINT memes_guild_metadata_id_key UNIQUE (guild, metadata_id);
+
+CREATE UNIQUE INDEX IF NOT EXISTS memes_guild_title_key ON memes (guild, title);
+CREATE UNIQUE INDEX IF NOT EXISTS memes_guild_content_image_id_audio_id_key ON memes (guild, content, image_id, audio_id);
+CREATE UNIQUE INDEX IF NOT EXISTS memes_guild_metadata_id_key ON memes (guild, metadata_id);
+
+ALTER TABLE tombstones
+    ADD COLUMN IF NOT EXISTS guild BIGINT;
+
+ALTER TABLE tombstones
+    ALTER COLUMN guild TYPE BIGINT;
+
+ALTER TABLE invocation_records
+    ADD COLUMN IF NOT EXISTS guild BIGINT;
+
+ALTER TABLE invocation_records
+    ALTER COLUMN guild TYPE BIGINT;
-- 
cgit v1.3.1

