-
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 diff changelog generating undesired changes (#679)
* fix: how a unique constraint is not unique!? * fix: primary key backing index issues. * fix: advanced validation for sequence fields managed by liquibase * fix: allow allocation size of 50 to be the same as null
- Loading branch information
1 parent
2ef942f
commit 36ad460
Showing
5 changed files
with
110 additions
and
3 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 { | ||
|
||
@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
37 changes: 37 additions & 0 deletions
37
src/main/java/liquibase/ext/hibernate/diff/ChangedUniqueConstraintChangeGenerator.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.UniqueConstraint; | ||
|
||
/** | ||
* Unique attribute for unique constraints backing index can have different values dependending on the database implementation, | ||
* so we suppress all unique constraint changes based on unique constraints. | ||
*/ | ||
public class ChangedUniqueConstraintChangeGenerator extends liquibase.diff.output.changelog.core.ChangedUniqueConstraintChangeGenerator { | ||
|
||
@Override | ||
public int getPriority(Class<? extends DatabaseObject> objectType, Database database) { | ||
if (UniqueConstraint.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
2 changes: 2 additions & 0 deletions
2
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
liquibase.ext.hibernate.diff.ChangedColumnChangeGenerator | ||
liquibase.ext.hibernate.diff.ChangedForeignKeyChangeGenerator | ||
liquibase.ext.hibernate.diff.ChangedPrimaryKeyChangeGenerator | ||
liquibase.ext.hibernate.diff.ChangedSequenceChangeGenerator | ||
liquibase.ext.hibernate.diff.ChangedUniqueConstraintChangeGenerator | ||
liquibase.ext.hibernate.diff.MissingSequenceChangeGenerator | ||
liquibase.ext.hibernate.diff.UnexpectedIndexChangeGenerator |