-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tgz: Implemented ColumnSnapshotGenerator to handle numeric boolean de…
…fault values in snapshots (#191) * tgz: Implemented ColumnSnapshotGenerator to handle numeric boolean default values in snapshots * ColumnSnapshotGeneratorHana, improved priority evaluation, restricting to HanaDatabase
- Loading branch information
1 parent
b5de41e
commit 73eb522
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/main/java/liquibase/ext/hana/snapshot/ColumnSnapshotGeneratorHana.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,47 @@ | ||
package liquibase.ext.hana.snapshot; | ||
|
||
import liquibase.database.Database; | ||
import liquibase.ext.hana.HanaDatabase; | ||
import liquibase.snapshot.CachedRow; | ||
import liquibase.snapshot.SnapshotGenerator; | ||
import liquibase.snapshot.jvm.ColumnSnapshotGenerator; | ||
import liquibase.statement.DatabaseFunction; | ||
import liquibase.structure.DatabaseObject; | ||
import liquibase.structure.core.Column; | ||
|
||
public class ColumnSnapshotGeneratorHana extends ColumnSnapshotGenerator { | ||
|
||
@Override | ||
public int getPriority(Class<? extends DatabaseObject> objectType, Database database) { | ||
if (!(database instanceof HanaDatabase)) { | ||
return PRIORITY_NONE; | ||
} | ||
int priority = super.getPriority(objectType, database); | ||
if (priority > PRIORITY_NONE) { | ||
priority += PRIORITY_DATABASE; | ||
} | ||
return priority; | ||
} | ||
|
||
@Override | ||
public Class<? extends SnapshotGenerator>[] replaces() { | ||
return new Class[]{ColumnSnapshotGenerator.class}; | ||
} | ||
|
||
@Override | ||
protected Object readDefaultValue(CachedRow columnMetadataResultSet, Column columnInfo, Database database) { | ||
Object defaultValue = super.readDefaultValue(columnMetadataResultSet, columnInfo, database); | ||
String typeName = columnMetadataResultSet.getString("TYPE_NAME").toUpperCase(); | ||
if ("BOOLEAN".equals(typeName)) { | ||
if (defaultValue instanceof DatabaseFunction) { | ||
String defaultAsString = ((DatabaseFunction) defaultValue).getValue(); | ||
if ("0".equals(defaultAsString)) { | ||
return "FALSE"; | ||
} else if ("1".equals(defaultAsString)) { | ||
return "TRUE"; | ||
} | ||
} | ||
} | ||
return defaultValue; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/main/resources/META-INF/services/liquibase.snapshot.SnapshotGenerator
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,2 +1,3 @@ | ||
liquibase.ext.hana.snapshot.SequenceSnapshotGeneratorHana | ||
liquibase.ext.hana.snapshot.UniqueConstraintSnapshotGeneratorHana | ||
liquibase.ext.hana.snapshot.ColumnSnapshotGeneratorHana |