Skip to content

bug(db): migration-release reconciliation misses constraints from already-applied migrations #456

Closed

Description

@imshashank

packages/db/tests/migration-release.test.ts › database release > does not silently baseline a missing webhook ownership constraint fails whenever exactly one new migration is pending and an earlier, already-applied migration is the one that actually owns the missing object.

Repro path found while investigating CI on #448: that PR adds 0027_friendly_bloodaxe.sql (the ai_usage table). The test drops webhook_delivery_processing_claim_check, a constraint created by 0026_breezy_johnny_storm.sql, then removes the latest migration from the ledger and runs releaseDatabase() expecting the constraint to be restored.

With only 0027 pending, reconcileNotificationChecks() (or the equivalent reconciliation step) is only given the pending migrations to work from. Since 0026 is already recorded as applied, the missing constraint it owns is invisible to reconciliation, and the constraint never gets recreated. This isn't specific to 0027 or to the AI provider work in #448, any PR that adds the next migration on top of main will trip the same test, since the failure depends on which migration is "latest" at merge time, not on anything the new migration itself does.

Root cause looks like reconciliation scoping itself to pending migrations only, when it needs to check the full set of declared schema objects regardless of which migration originally created them (consistent with how bun run db:release is documented to compare columns, types, defaults, indexes, foreign keys, etc. against the declared schema as a whole, not migration-by-migration).

Flagged from #448's thread: #448 (comment) (original diagnosis by @Pallavikumarimdb: #448 (comment)).

Activity

  1. added a commit that references this issue on Sep 10, 2026
    b8e35b7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions