fix: make gateway migrations idempotent + self-heal drizzle history
Prevent recurring infinite restart loop (389x crash) caused by drizzle re-applying already-applied migrations when public.__drizzle_migrations tracking is empty/partial. - 0017/0018: ADD COLUMN IF NOT EXISTS (re-run safe) - 0019: DO-block rename that handles all prior states (server_name-only, both columns, or server_nick-only) so it never errors or double-renames - seedDrizzleHistory: reconcile tracked created_at to the journal's latest 'when' when the schema already reflects the latest migration, instead of early-returning on an existing-but-empty/partial tracking table
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
ALTER TABLE "moderation_actions" ADD COLUMN "username" text;
|
||||
ALTER TABLE "moderation_actions" ADD COLUMN IF NOT EXISTS "username" text;
|
||||
--> statement-breakpoint
|
||||
-- Backfill username from messages table for existing actions
|
||||
UPDATE "moderation_actions" a
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
ALTER TABLE "moderation_actions" ADD COLUMN "server_name" text;
|
||||
ALTER TABLE "moderation_actions" ADD COLUMN IF NOT EXISTS "server_name" text;
|
||||
|
||||
+23
-1
@@ -1,4 +1,26 @@
|
||||
-- Rename server_name (guild name) -> server_nick (member's server nickname)
|
||||
-- server_name was added in 0018 but never populated (all NULL), so renaming
|
||||
-- the empty column is safe and keeps retention semantics correct.
|
||||
ALTER TABLE "moderation_actions" RENAME COLUMN "server_name" TO "server_nick";
|
||||
-- Idempotent across all possible prior states:
|
||||
-- • server_name present, server_nick absent -> rename
|
||||
-- • both present (backfill created server_nick) -> drop the stale server_name
|
||||
-- • server_nick present only -> already done, no-op
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_name = 'moderation_actions' AND column_name = 'server_name'
|
||||
) AND NOT EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_name = 'moderation_actions' AND column_name = 'server_nick'
|
||||
) THEN
|
||||
ALTER TABLE "moderation_actions" RENAME COLUMN "server_name" TO "server_nick";
|
||||
ELSIF EXISTS (
|
||||
SELECT 1 FROM information_schema.columns
|
||||
WHERE table_name = 'moderation_actions' AND column_name = 'server_name'
|
||||
) THEN
|
||||
-- server_nick already exists (e.g. backfilled out-of-band) — drop the
|
||||
-- now-redundant server_name column instead of renaming into a conflict.
|
||||
ALTER TABLE "moderation_actions" DROP COLUMN "server_name";
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
Reference in New Issue
Block a user