Handle the fact that FK names are not always unique. #2228
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Update ForeignKeyComparator logic to work like PrimaryKeyComparitor which already assumes primary key names are only unique within the table name.
Fixes #2227
Dev Handoff Notes (Internal Use)
Links
Testing
Dev Verification
With the change, I get
Test Requirements (Liquibase Internal QA)
You need two Postgres instances to test this fix. Postgres version does not matter; I reproed using a PG 12 and a PG 9.
Setup:
On one PG instance, execute the following SQL:
On the second PG instance, execute the following SQL:
The difference is the missing foreign key on table2 on the second instance.
Manual Tests
Verify liquibase diff shows a unexpected foreign key fk_test_fk from table2(id) to table1(id).
Verify liquibase diffChangeLog has an ALTER TABLE to drop a foreign key fk_test_fk from table2(id) to table1(id).
ALTER TABLE table2 DROP FOREIGN KEY fk_test_fk;
Verify reversing the order of the diff shows an missing foreign key fk_test_fk from table2(id) to table1(id).
Verify reversing the order of databases during diff-changelog generates a ALTER TABLE to add a foreign key fk_test_fk from table2(id) to table1(id).
alter table table2 add constraint fk_test_fk FOREIGN KEY (id) references table1(id);
Verify liquibase update using changelog gcl_dropFK.postgres.sql correctly drops the foreign key from the first database.
(Note: I added this test case because I have a suspicion that if the SQL to drop the FK will throw an error on update because there are two “fk_test_fk” foreign keys on table1. If there is no error during update itself, verify that the correct/expected foreign key is dropped.)
Automated Tests
┆Issue is synchronized with this Jira Bug by Unito