Repository navigation
Fixes #39793: stale foreign keys no longer block schema restore (backport 2.0 #39812) - #39843
Conversation
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
Code Review ✅ Approved 🟡 Medium riskAllowing unchanged foreign keys to reference removed columns may preserve stale relationship metadata during restores, while new or edited keys remain validated. Backports the fix so a soft-deleted schema can be restored when a table stores a foreign key to a column that was later removed. Stale foreign keys are kept with a logged warning, and new foreign keys to missing columns now return a 400 error that names the table. No issues found. VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
Issue
Partial cherry-pick of #39812 (Fixes #39793) onto 2.0.
Restoring a soft-deleted schema failed with
Invalid column name <col>when a table in it had a foreign key to a column that was later removed from another table. 2.0.10 has the bug.What this PR changes
Invalid column name pos_id in table <fqn>.This is what makes the restore from the report succeed.
Not in this PR, and why
#39812 also drops the foreign keys in other tables when a column is removed. That part is left out on purpose. It must run only on the first diff pass of an update: session consolidation replays the same diff against older versions of the table, and there a column can wrongly look removed. 2.0 has no way to tell the first pass from a replay (main has it), and adding it is too large for a patch branch. Without that guard the cleanup could drop a foreign key that still points to an existing column.
On 2.0, removing a column still leaves the stale key on the other table. It no longer blocks a restore or any other write.
Differences from main
assertThrows, because 2.0 has noApiAssertions.TableRepositorywere around code that main changed after 2.0 branched.Tests
Backend integration tests, in
TableResourceIT:Both new tests and the 3 existing column-removal tests pass on MySQL (5 of 5) on this branch. Both new tests fail on the original 2.0 code; the restore fails with the reported
Invalid column name pos_id.Not run: Postgres and the rest of
TableResourceITon 2.0.