Skip to content

fix(db): repair stale migration snapshots after the #6606 merge - #6653

Merged
iscekic merged 1 commit into
mainfrom
fix/repair-live-activity-migration-snapshot
Sep 23, 2026
Merged

iscekic merged 1 commit into
mainfrom
fix/repair-live-activity-migration-snapshot

Conversation

@iscekic

@iscekic iscekic commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

Repairs the migration metadata left inconsistent by the merge that brought the Live Activity migrations onto main.

Problem

The merge bdd0a95b8b resolved the _journal.json and 0255_snapshot.json conflicts, but left 0256_snapshot.json stale:

  • 0255_snapshot.json correctly records repository_customizations as dropped.
  • 0256_snapshot.json records it as present again, so drizzle generate emits a spurious DROP TABLE "repository_customizations" CASCADE;.
  • The journal has idx 257 with tag 0256_..., but no 0257_snapshot.json. packages/db/src/schema.test.ts derives the snapshot path from idx, so it reads a missing file.

Change

  • Renumber the two Live Activity migrations so each tag prefix matches its journal idx:
    • 0255_add_superseded_at_to_user_activity_tokens.sql → 0256_...
    • 0256_user_activity_tokens_live_ios_activity_unique.sql → 0257_...
  • Rebuild the tail snapshots to match each migration state:
    • 0255_snapshot.json: after DROP repository_customizations
    • 0256_snapshot.json: after ADD COLUMN superseded_at
    • 0257_snapshot.json: after the partial unique index
  • Journal when values are unchanged, so already-applied migrations are not re-run (the migrator records hash + created_at only).

Verification

  • drizzle-kit check: no collisions.
  • drizzle generate diff: 0 pending statements.
  • pnpm --filter @kilocode/db test (DB-less): 7 suites, 32 tests pass.
  • The DB-backed schema.test.ts assertion was reproduced without a database: the idx-derived 0257_snapshot.json exists and yields 0 statements.

Note

This edits generated migration metadata. packages/db/AGENTS.md normally forbids that, but regeneration cannot reconstruct already-merged history without re-running ADD COLUMN on databases that already applied it.

The merge that brought the Live Activity migrations onto main (bdd0a95)
resolved the `_journal.json` and `0255_snapshot.json` conflicts, but left
`0256_snapshot.json` stale. It still recorded `repository_customizations`,
which #6558 had dropped, so `drizzle generate` emitted a spurious
`DROP TABLE "repository_customizations" CASCADE;` against a table that no
longer exists.

Also renumber the two Live Activity migrations so each tag prefix matches
its journal idx, and rebuild the tail snapshots to match each migration
state. The journal `when` values are unchanged, so already-applied
migrations are not re-run.

- 0255_snapshot.json: state after DROP repository_customizations
- 0256_snapshot.json: state after ADD COLUMN superseded_at
- 0257_snapshot.json: state after the partial unique index
@iscekic iscekic self-assigned this Sep 23, 2026
@kilo-code-bot

kilo-code-bot Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Reviewed the migration metadata repair. The two .sql files are pure renames (0 content changes), and the renumbering is internally consistent: journal idx 255/256/257 now map to 0255_drop_repository_customizations, 0256_add_superseded_at_to_user_activity_tokens, and 0257_user_activity_tokens_live_ios_activity_unique, and each tag has a matching .sql file.

Verified the snapshot chain (0254 → 0255 → 0256 → 0257) is coherent: 0256 = 0255 + superseded_at, 0257 = 0256 + the partial unique index, prevId links match, and no snapshot still references the removed repository_customizations table or the old 0256 id. schema.test.ts derives its snapshot path from the last journal idx (257), which now exists. Renaming tags is safe for already-applied migrations because Drizzle compares journal when/folderMillis against the newest __drizzle_migrations.created_at, not the tag, and the when values are unchanged.

Files Reviewed (6 files)
  • packages/db/src/migrations/0256_add_superseded_at_to_user_activity_tokens.sql (renamed, content unchanged)
  • packages/db/src/migrations/0257_user_activity_tokens_live_ios_activity_unique.sql (renamed, content unchanged)
  • packages/db/src/migrations/meta/0255_snapshot.json
  • packages/db/src/migrations/meta/0256_snapshot.json
  • packages/db/src/migrations/meta/0257_snapshot.json
  • packages/db/src/migrations/meta/_journal.json

Reviewed by deepseek-v4.1-flash · Input: 0 · Output: 0 · Cached: 0

Review guidance: REVIEW.md from base branch main

@iscekic iscekic added the human-ready The PR is ready for human review. label Sep 23, 2026
@iscekic
iscekic enabled auto-merge (squash) September 23, 2026 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

human-ready The PR is ready for human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants