fix(db): make document revision migration replay-safe

This commit is contained in:
dotta 2026-03-31 08:09:00 -05:00
parent 761dce559d
commit 90889c12d8
2 changed files with 79 additions and 5 deletions

View file

@ -1,9 +1,11 @@
ALTER TABLE "document_revisions" ADD COLUMN "title" text;--> statement-breakpoint
ALTER TABLE "document_revisions" ADD COLUMN "format" text DEFAULT 'markdown' NOT NULL;
ALTER TABLE "document_revisions" ADD COLUMN IF NOT EXISTS "title" text;--> statement-breakpoint
ALTER TABLE "document_revisions" ADD COLUMN IF NOT EXISTS "format" text;--> statement-breakpoint
ALTER TABLE "document_revisions" ALTER COLUMN "format" SET DEFAULT 'markdown';
--> statement-breakpoint
UPDATE "document_revisions" AS "dr"
SET
"title" = "d"."title",
"format" = COALESCE("d"."format", 'markdown')
"title" = COALESCE("dr"."title", "d"."title"),
"format" = COALESCE("dr"."format", "d"."format", 'markdown')
FROM "documents" AS "d"
WHERE "d"."id" = "dr"."document_id";
WHERE "d"."id" = "dr"."document_id";--> statement-breakpoint
ALTER TABLE "document_revisions" ALTER COLUMN "format" SET NOT NULL;