Repository navigation
Fixes #39793: stale foreign keys no longer block schema restore (backport 2.1 #39812) - #39844
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 |
| private void removeConstraintsReferringTo(Table table, Set<String> removedColumns) { | ||
| if (removedColumns.isEmpty()) { | ||
| return; | ||
| } | ||
| List<EntityReference> referrers = | ||
| findFrom(table.getId(), TABLE, Relationship.RELATED_TO, TABLE, ALL); | ||
| for (EntityReference referrer : referrers) { | ||
| if (!referrer.getId().equals(table.getId())) { | ||
| dropConstraintsReferringTo(referrer.getId(), table, removedColumns); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void dropConstraintsReferringTo( | ||
| UUID referrerId, Table table, Set<String> removedColumns) { |
There was a problem hiding this comment.
⚠️ Quality: New helpers use guard-clause returns, contradicting the returns-once ADR
Two new helpers break ADR:2026-11-20-a-method-returns-once, which says void methods have no return and no guard clauses. removeConstraintsReferringTo opens with if (removedColumns.isEmpty()) { return; }, and dropConstraintsReferringTo returns early with if (kept.size() == stored.size()) { return; }. The review rules treat a contradiction of an Accepted record as blocking. Either wrap the work in the condition that allows it, or add a record that supersedes the ADR. The empty-set guard isn't needed anyway: with an empty set, refersToRemovedColumn never matches, so nothing gets written.
Put the work inside the allowing condition instead of returning early:
private void removeConstraintsReferringTo(Table table, Set<String> removedColumns) {
if (!removedColumns.isEmpty()) {
findFrom(table.getId(), TABLE, Relationship.RELATED_TO, TABLE, ALL).stream()
.filter(referrer -> !referrer.getId().equals(table.getId()))
.forEach(referrer -> dropConstraintsReferringTo(referrer.getId(), table, removedColumns));
}
}
// in dropConstraintsReferringTo:
if (kept.size() != stored.size()) {
persistKeptConstraints(original, kept, table);
LOG.info(...);
}
Was this helpful? React with 👍 / 👎
Code Review
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source
Issue
Cherry-pick of #39812 (Fixes #39793) onto 2.1.
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.1.1 has the bug.What this PR changes
The same change as #39812, applied cleanly:
Invalid column name pos_id in table <fqn>.Differences from main
One import (
Relationship) added toTableResourceIT. The 2.1 copy of that file did not import it, and a new test helper uses it. The production change is identical to main (same patch id).Tests
Backend integration tests, in
TableResourceIT:The 5 new tests and the 3 existing column-removal tests pass on MySQL (8 of 8) on this branch. The same tests were proven red on the old code on main (4 of the 5 fail there).
Not run: Postgres and the rest of
TableResourceITon 2.1.