fix(prisma): make restore_todos_table migration idempotent #63
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "claude/suspicious-dirac-2e2511"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
prisma/migrations/20260506101436_restore_todos_table/migration.sqlin aDO $$ ... EXCEPTION WHEN duplicate_table THEN NULL ... $$block so it no-ops whentodosalready exists.prisma migrate dev --create-onlyfor any new migration; previous workaround wasdb execute + migrate resolve --applied(last hit in #62).Why CREATE TABLE IF NOT EXISTS alone isn't enough
The init migration also creates the
todos_user_id_done_archived_idxindex andtodos_user_id_fkeyFK;add_todo_product_idadds the second index and FK. All four would conflict during shadow replay, not just CREATE TABLE. The DO block cleanly no-ops the whole migration when the table already exists.Verification
Created a temporary
scrum4me_shadow_testDB on the dev server, ran:Exit code 0; 1134 lines of replay SQL — every migration (including this one) replayed cleanly. Sequence in the shadow DB:
20260424123750_initcreatestodos20260506101436_restore_todos_table(this fix) hitsduplicate_table→ handler catches → block exits → next migration runs20260507000000_migrate_todos_to_ideaslater dropstodosShadow DB dropped afterward; no test migration directory created.
Out of scope
Pre-existing drift on the dev DB (tables
FlowRun/Session/FlowStep/User/WorkerEvent/WorkerRun, enumsEventKind/FlowStatus/MetaTag/RunStatus, and 7 migrations applied to the DB but missing fromprisma/migrations/— including a second20260513150226_init) — flagged separately, not addressed here.Test plan
npx prisma migrate dev --create-only --name verify_fixagainst a clean shadow DB after this PR — should succeed without intervention.