aboutsummaryrefslogtreecommitdiff
path: root/migrations/2024-08-16-230507_require_guild
diff options
context:
space:
mode:
authorNathan Perry <np@nathanperry.dev>2024-08-16 21:14:30 -0400
committerNathan Perry <np@nathanperry.dev>2024-08-16 21:15:07 -0400
commitef056edf92b678265a4666e1f9405e3b0ce66a42 (patch)
treeb3766d47ae2898d2a46f108de4e2be0ede6c400b /migrations/2024-08-16-230507_require_guild
parentc5ce454319a7d54d3967c6ea7695543e943a37b2 (diff)
repo: overhaul for multitenancy
Diffstat (limited to 'migrations/2024-08-16-230507_require_guild')
-rw-r--r--migrations/2024-08-16-230507_require_guild/down.sql6
-rw-r--r--migrations/2024-08-16-230507_require_guild/up.sql22
2 files changed, 28 insertions, 0 deletions
diff --git a/migrations/2024-08-16-230507_require_guild/down.sql b/migrations/2024-08-16-230507_require_guild/down.sql
new file mode 100644
index 0000000..e7191c8
--- /dev/null
+++ b/migrations/2024-08-16-230507_require_guild/down.sql
@@ -0,0 +1,6 @@
+ALTER TABLE memes
+ ALTER COLUMN guild DROP NOT NULL;
+ALTER TABLE invocation_records
+ ALTER COLUMN guild DROP NOT NULL;
+ALTER TABLE tombstones
+ ALTER COLUMN guild DROP NOT NULL;
diff --git a/migrations/2024-08-16-230507_require_guild/up.sql b/migrations/2024-08-16-230507_require_guild/up.sql
new file mode 100644
index 0000000..06e5cd3
--- /dev/null
+++ b/migrations/2024-08-16-230507_require_guild/up.sql
@@ -0,0 +1,22 @@
+-- This migration will fail with any records in the db. If you are working with a normal server, you
+-- can run:
+--
+-- $ convert_null_guilds --guild $PREVIOUS_SINGLETENANT_GUILD
+--
+-- to set all existing db records to the specified guild. A mixed / fucked up db sceneario will
+-- require you to manually edit the db and ensure `guild` is set in `memes`, `invocation_records`,
+-- and `tombstones`.
+
+DO LANGUAGE plpgsql
+$$
+ BEGIN
+ RAISE NOTICE 'if this migration fails, consider running "convert_null_guilds"';
+ END
+$$;
+
+ALTER TABLE memes
+ ALTER COLUMN guild SET NOT NULL;
+ALTER TABLE invocation_records
+ ALTER COLUMN guild SET NOT NULL;
+ALTER TABLE tombstones
+ ALTER COLUMN guild SET NOT NULL;