diff --git a/src/shared/infrastructure/database/migrations/0004_brainy_rocket_racer.sql b/src/shared/infrastructure/database/migrations/0004_brainy_rocket_racer.sql index b80d33bf..10696b5f 100644 --- a/src/shared/infrastructure/database/migrations/0004_brainy_rocket_racer.sql +++ b/src/shared/infrastructure/database/migrations/0004_brainy_rocket_racer.sql @@ -1,5 +1,6 @@ ALTER TABLE "cards" RENAME COLUMN "original_published_record_id" TO "published_record_id";--> statement-breakpoint ALTER TABLE "cards" DROP CONSTRAINT "cards_original_published_record_id_published_records_id_fk"; --> statement-breakpoint +TRUNCATE TABLE "cards" CASCADE;--> statement-breakpoint ALTER TABLE "cards" ADD COLUMN "author_id" text NOT NULL;--> statement-breakpoint -ALTER TABLE "cards" ADD CONSTRAINT "cards_published_record_id_published_records_id_fk" FOREIGN KEY ("published_record_id") REFERENCES "public"."published_records"("id") ON DELETE no action ON UPDATE no action; \ No newline at end of file +ALTER TABLE "cards" ADD CONSTRAINT "cards_published_record_id_published_records_id_fk" FOREIGN KEY ("published_record_id") REFERENCES "public"."published_records"("id") ON DELETE no action ON UPDATE no action; -- 2.51.2 From 839826198e6ad1e6d15fbd55b25e731cc3406e26 Mon Sep 17 00:00:00 2001 From: Wesley Finck Date: Thu, 9 Oct 2025 16:02:26 -0700 Subject: [PATCH 2/3] refactor: update migration 0004 to truncate all related tables Co-authored-by: aider (anthropic/claude-sonnet-4-5-20250929) --- .../database/migrations/0004_brainy_rocket_racer.sql | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/shared/infrastructure/database/migrations/0004_brainy_rocket_racer.sql b/src/shared/infrastructure/database/migrations/0004_brainy_rocket_racer.sql index 10696b5f..670a1bdb 100644 --- a/src/shared/infrastructure/database/migrations/0004_brainy_rocket_racer.sql +++ b/src/shared/infrastructure/database/migrations/0004_brainy_rocket_racer.sql @@ -1,6 +1,12 @@ ALTER TABLE "cards" RENAME COLUMN "original_published_record_id" TO "published_record_id";--> statement-breakpoint ALTER TABLE "cards" DROP CONSTRAINT "cards_original_published_record_id_published_records_id_fk"; --> statement-breakpoint -TRUNCATE TABLE "cards" CASCADE;--> statement-breakpoint +TRUNCATE TABLE "collection_cards", +"collection_collaborators", +"library_memberships", +"collections", +"cards", +"published_records", +"feed_activities" CASCADE;--> statement-breakpoint ALTER TABLE "cards" ADD COLUMN "author_id" text NOT NULL;--> statement-breakpoint ALTER TABLE "cards" ADD CONSTRAINT "cards_published_record_id_published_records_id_fk" FOREIGN KEY ("published_record_id") REFERENCES "public"."published_records"("id") ON DELETE no action ON UPDATE no action; -- 2.51.2 From 4dcf894c3e35a40e49371aee3ad7bb29e84feccc Mon Sep 17 00:00:00 2001 From: Wesley Finck Date: Thu, 9 Oct 2025 16:05:39 -0700 Subject: [PATCH 3/3] update migration script to truncate db first then add field --- .../migrations/0004_brainy_rocket_racer.sql | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/shared/infrastructure/database/migrations/0004_brainy_rocket_racer.sql b/src/shared/infrastructure/database/migrations/0004_brainy_rocket_racer.sql index 670a1bdb..5b74c9cc 100644 --- a/src/shared/infrastructure/database/migrations/0004_brainy_rocket_racer.sql +++ b/src/shared/infrastructure/database/migrations/0004_brainy_rocket_racer.sql @@ -1,12 +1,17 @@ -ALTER TABLE "cards" RENAME COLUMN "original_published_record_id" TO "published_record_id";--> statement-breakpoint -ALTER TABLE "cards" DROP CONSTRAINT "cards_original_published_record_id_published_records_id_fk"; ---> statement-breakpoint TRUNCATE TABLE "collection_cards", "collection_collaborators", "library_memberships", "collections", "cards", "published_records", -"feed_activities" CASCADE;--> statement-breakpoint -ALTER TABLE "cards" ADD COLUMN "author_id" text NOT NULL;--> statement-breakpoint -ALTER TABLE "cards" ADD CONSTRAINT "cards_published_record_id_published_records_id_fk" FOREIGN KEY ("published_record_id") REFERENCES "public"."published_records"("id") ON DELETE no action ON UPDATE no action; +"feed_activities" CASCADE; +--> statement-breakpoint +ALTER TABLE "cards" +RENAME COLUMN "original_published_record_id" TO "published_record_id"; +--> statement-breakpoint +ALTER TABLE "cards" +DROP CONSTRAINT "cards_original_published_record_id_published_records_id_fk"; +--> statement-breakpoint +ALTER TABLE "cards" ADD COLUMN "author_id" text NOT NULL; +--> statement-breakpoint +ALTER TABLE "cards" ADD CONSTRAINT "cards_published_record_id_published_records_id_fk" FOREIGN KEY ("published_record_id") REFERENCES "public"."published_records"("id") ON DELETE no action ON UPDATE no action; \ No newline at end of file