Skip to content

db apply --force now fails with 409 on a stale FK from a long-removed relationship (surfaced after #52's fix) #63

Description

@Katomil

Summary

After the fix for #52 (bare 500 on db apply's real-commit step), rayfin up db apply --force now returns a specific error instead of the old opaque one — but the error points at a foreign key that no longer exists anywhere in the live database, and the suggested remediation isn't actionable.

Environment

Repro

  1. Have an entity with a @one(() => Target) relationship field, generating an FK column/constraint.
  2. Refactor that field to a plain scalar (a legitimate schema change — in our case, @one(() => Product) became a denormalized @text() part-number field).
  3. rayfin up db apply (no force) — fails cleanly with an unrelated destructive-change 400 guard on other pending drops. Expected.
  4. rayfin up db apply --force.

Expected

Migration reconciles current entity state against actual live DB state, and applies cleanly (or fails referencing objects that actually exist).

Actual

❌ Failed to apply configuration to remote endpoint
   DAB server responded with error: 409 Conflict
   Details: The migration expected a database object that no longer exists — the database may have been changed outside Rayfin. Database reported: "'FK_DqExceptionProducts_product_id' is not a constraint.
Could not drop constraint. See previous errors.".
   RootActivityId: b0fc839e-6afc-4eb7-9e9f-1e6bcf08b0f0

Queried the live warehouse directly (sys.foreign_keys, sys.columns): no product_id column exists on the table, no FK_DqExceptionProducts_product_id constraint exists under any name — only FK_DqExceptionProducts_rule_id is real. The error's own suggested fix ("Restore the object, then re-apply") isn't actionable: there's no product_id column left in the current entity model to restore a matching FK to.

This looks like Rayfin's server-side tracked deployment/migration history for this item still references a relationship removed from the entity definitions a while ago, and reconciliation assumes that object still exists rather than diffing against the DB's actual current state.

Additional context

Metadata

Metadata

Labels

bugSomething isn't workingissue-mappedIssue is mapped to internal trackertriaged

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions