-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: primary key backing index issues.
- Loading branch information
1 parent
b493b5d
commit 822ee04
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
src/main/java/liquibase/ext/hibernate/diff/ChangedPrimaryKeyChangeGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package liquibase.ext.hibernate.diff; | ||
|
||
import liquibase.change.Change; | ||
import liquibase.database.Database; | ||
import liquibase.diff.ObjectDifferences; | ||
import liquibase.diff.output.DiffOutputControl; | ||
import liquibase.diff.output.changelog.ChangeGeneratorChain; | ||
import liquibase.ext.hibernate.database.HibernateDatabase; | ||
import liquibase.structure.DatabaseObject; | ||
import liquibase.structure.core.PrimaryKey; | ||
|
||
/** | ||
* Hibernate doesn't know about all the variations that occur with primary keys, especially backing index stuff. | ||
* To prevent changing customized primary keys, we suppress this kind of changes from hibernate side. | ||
*/ | ||
public class ChangedPrimaryKeyChangeGenerator extends liquibase.diff.output.changelog.core.ChangedPrimaryKeyChangeGenerator { | ||
Check notice Code scanning / CodeQL Class has same name as super class Note
ChangedPrimaryKeyChangeGenerator has the same name as its supertype
liquibase.diff.output.changelog.core.ChangedPrimaryKeyChangeGenerator Error loading related location Loading |
||
|
||
@Override | ||
public int getPriority(Class<? extends DatabaseObject> objectType, Database database) { | ||
if (PrimaryKey.class.isAssignableFrom(objectType)) { | ||
return PRIORITY_ADDITIONAL; | ||
} | ||
return PRIORITY_NONE; | ||
} | ||
|
||
@Override | ||
public Change[] fixChanged(DatabaseObject changedObject, ObjectDifferences differences, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) { | ||
if (referenceDatabase instanceof HibernateDatabase || comparisonDatabase instanceof HibernateDatabase) { | ||
differences.removeDifference("unique"); | ||
if (!differences.hasDifferences()) { | ||
return null; | ||
} | ||
} | ||
|
||
return super.fixChanged(changedObject, differences, control, referenceDatabase, comparisonDatabase, chain); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/main/resources/META-INF/services/liquibase.diff.output.changelog.ChangeGenerator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters