ReviewOS

stacks/bun-query-builder

Migration diff ignores foreign-key (references) changes — columnsAreDifferent omits references

#1037
Closed glennmichael123 opened this 22 days ago · 0 comments
22 days ago

Summary

columnsAreDifferent compares type/nullable/default/unique/enum but never col.references. Adding, removing, or changing a FK target or onDelete/onUpdate on an existing column produces no diff, so generateDiffSql emits nothing.

Evidence (repro)

belongsTo: ['User'] -> belongsTo: [{ model:'User', onDelete:'cascade' }]  =>  "-- No changes detected"

Location

src/migrations.ts:~895-917.

Suggested fix

Compare references (table/column/onDelete/onUpdate) in columnsAreDifferent and emit addForeignKey/drop-constraint statements on diff. (SQLite can't ALTER ... ADD CONSTRAINT — needs the table-rebuild path or a documented limitation.)

Severity: medium/high. Found via internal code audit.

Sign in to comment on this issue.