use of liquibase.diff.Difference in project liquibase by liquibase.
the class ChangedTableChangeGenerator method fixChanged.
@Override
public Change[] fixChanged(DatabaseObject changedObject, ObjectDifferences differences, DiffOutputControl control, Database referenceDatabase, final Database comparisonDatabase, ChangeGeneratorChain chain) {
Table table = (Table) changedObject;
Difference changedRemarks = differences.getDifference("remarks");
if (changedRemarks != null) {
SetTableRemarksChange change = new SetTableRemarksChange();
if (control.getIncludeCatalog()) {
change.setCatalogName(table.getSchema().getCatalogName());
}
if (control.getIncludeSchema()) {
change.setSchemaName(table.getSchema().getName());
}
change.setTableName(table.getName());
change.setRemarks(table.getRemarks());
return new Change[] { change };
}
Difference changedTablespace = differences.getDifference("tablespace");
if (changedTablespace != null) {
// TODO: Implement moveTableToDifferentTablespace change type!
Scope.getCurrentScope().getLog(getClass()).warning("A change of the tablespace was detected, however, Liquibase does not currently generate statements to move a table between tablespaces.");
}
return null;
}
use of liquibase.diff.Difference in project liquibase by liquibase.
the class ChangedColumnChangeGenerator method handleNullableDifferences.
protected void handleNullableDifferences(Column column, ObjectDifferences differences, DiffOutputControl control, List<Change> changes, Database referenceDatabase, Database comparisonDatabase) {
Difference nullableDifference = differences.getDifference("nullable");
if ((nullableDifference != null) && (nullableDifference.getReferenceValue() != null)) {
boolean nullable = (Boolean) nullableDifference.getReferenceValue();
if (nullable) {
DropNotNullConstraintChange change = new DropNotNullConstraintChange();
if (control.getIncludeCatalog()) {
change.setCatalogName(column.getRelation().getSchema().getCatalog().getName());
}
if (control.getIncludeSchema()) {
change.setSchemaName(column.getRelation().getSchema().getName());
}
change.setTableName(column.getRelation().getName());
change.setColumnName(column.getName());
change.setColumnDataType(DataTypeFactory.getInstance().from(column.getType(), comparisonDatabase).toString());
changes.add(change);
} else {
AddNotNullConstraintChange change = new AddNotNullConstraintChange();
if (control.getIncludeCatalog()) {
change.setCatalogName(column.getRelation().getSchema().getCatalog().getName());
}
if (control.getIncludeSchema()) {
change.setSchemaName(column.getRelation().getSchema().getName());
}
change.setTableName(column.getRelation().getName());
change.setColumnName(column.getName());
change.setColumnDataType(DataTypeFactory.getInstance().from(column.getType(), comparisonDatabase).toString());
change.setValidate(column.getValidate());
change.setConstraintName(column.getAttribute("notNullConstraintName", String.class));
changes.add(change);
}
}
}
use of liquibase.diff.Difference in project liquibase by liquibase.
the class ChangedColumnChangeGenerator method handleAutoIncrementDifferences.
protected void handleAutoIncrementDifferences(Column column, ObjectDifferences differences, DiffOutputControl control, List<Change> changes, Database referenceDatabase, Database comparisonDatabase) {
Difference difference = differences.getDifference("autoIncrementInformation");
if (difference != null) {
if (difference.getReferenceValue() == null) {
Scope.getCurrentScope().getLog(getClass()).info("ChangedColumnChangeGenerator cannot fix dropped auto increment values");
// todo: Support dropping auto increments
} else {
AddAutoIncrementChange change = new AddAutoIncrementChange();
if (control.getIncludeCatalog()) {
change.setCatalogName(column.getRelation().getSchema().getCatalog().getName());
}
if (control.getIncludeSchema()) {
change.setSchemaName(column.getRelation().getSchema().getName());
}
change.setTableName(column.getRelation().getName());
change.setColumnName(column.getName());
change.setColumnDataType(DataTypeFactory.getInstance().from(column.getType(), comparisonDatabase).toString());
changes.add(change);
}
}
}
use of liquibase.diff.Difference in project liquibase by liquibase.
the class ChangedColumnChangeGenerator method handleDefaultValueDifferences.
protected void handleDefaultValueDifferences(Column column, ObjectDifferences differences, DiffOutputControl control, List<Change> changes, Database referenceDatabase, Database comparisonDatabase) {
Difference difference = differences.getDifference("defaultValue");
if (difference != null) {
Object value = difference.getReferenceValue();
LiquibaseDataType columnDataType = DataTypeFactory.getInstance().from(column.getType(), comparisonDatabase);
if (value == null) {
DropDefaultValueChange change = new DropDefaultValueChange();
if (control.getIncludeCatalog()) {
change.setCatalogName(column.getRelation().getSchema().getCatalog().getName());
}
if (control.getIncludeSchema()) {
change.setSchemaName(column.getRelation().getSchema().getName());
}
change.setTableName(column.getRelation().getName());
change.setColumnName(column.getName());
change.setColumnDataType(columnDataType.toString());
changes.add(change);
} else if (shouldTriggerAddDefaultChange(column, difference, comparisonDatabase)) {
AddDefaultValueChange change = new AddDefaultValueChange();
if (control.getIncludeCatalog()) {
change.setCatalogName(column.getRelation().getSchema().getCatalog().getName());
}
if (control.getIncludeSchema()) {
change.setSchemaName(column.getRelation().getSchema().getName());
}
change.setTableName(column.getRelation().getName());
change.setColumnName(column.getName());
change.setColumnDataType(columnDataType.toString());
//
if (value instanceof Boolean || columnDataType instanceof BooleanType) {
if (value instanceof Boolean) {
change.setDefaultValueBoolean((Boolean) value);
} else if (columnDataType instanceof BooleanType) {
if (value instanceof DatabaseFunction) {
if (value.equals(new DatabaseFunction("'false'"))) {
change.setDefaultValueBoolean(false);
} else if (value.equals(new DatabaseFunction("'true'"))) {
change.setDefaultValueBoolean(true);
} else {
change.setDefaultValueComputed(((DatabaseFunction) value));
}
}
}
} else if (value instanceof Date) {
change.setDefaultValueDate(new ISODateFormat().format(((Date) value)));
} else if (value instanceof Number) {
change.setDefaultValueNumeric(value.toString());
} else if (value instanceof DatabaseFunction) {
change.setDefaultValueComputed(((DatabaseFunction) value));
} else {
change.setDefaultValue(value.toString());
}
change.setDefaultValueConstraintName(column.getDefaultValueConstraintName());
changes.add(change);
}
}
}
use of liquibase.diff.Difference in project liquibase by liquibase.
the class ChangedViewChangeGenerator method fixChanged.
@Override
public Change[] fixChanged(DatabaseObject changedObject, ObjectDifferences differences, DiffOutputControl control, Database referenceDatabase, final Database comparisonDatabase, ChangeGeneratorChain chain) {
View view = (View) changedObject;
CreateViewChange change = createViewChange();
change.setViewName(view.getName());
change.setReplaceIfExists(true);
if (control.getIncludeCatalog()) {
change.setCatalogName(view.getSchema().getCatalogName());
}
if (control.getIncludeSchema()) {
change.setSchemaName(view.getSchema().getName());
}
String selectQuery = view.getDefinition();
boolean fullDefinitionOverridden = false;
if (selectQuery == null) {
selectQuery = "COULD NOT DETERMINE VIEW QUERY";
} else if ((comparisonDatabase instanceof OracleDatabase) && (view.getColumns() != null) && !view.getColumns().isEmpty()) {
String viewName;
if ((change.getCatalogName() == null) && (change.getSchemaName() == null)) {
viewName = comparisonDatabase.escapeObjectName(change.getViewName(), View.class);
} else {
viewName = comparisonDatabase.escapeViewName(change.getCatalogName(), change.getSchemaName(), change.getViewName());
}
selectQuery = "CREATE OR REPLACE FORCE VIEW " + viewName + " (" + StringUtil.join(view.getColumns(), ", ", new StringUtil.StringUtilFormatter() {
@Override
public String toString(Object obj) {
if ((((Column) obj).getComputed() != null) && ((Column) obj).getComputed()) {
return ((Column) obj).getName();
} else {
return comparisonDatabase.escapeColumnName(null, null, null, ((Column) obj).getName(), false);
}
}
}) + ") AS " + selectQuery;
change.setFullDefinition(true);
fullDefinitionOverridden = true;
}
change.setSelectQuery(selectQuery);
if (!fullDefinitionOverridden) {
change.setFullDefinition(view.getContainsFullDefinition());
}
List<Change> changes = new ArrayList<>();
changes.add(change);
Difference changedRemarks = differences.getDifference("remarks");
if (changedRemarks != null) {
SetTableRemarksChange setRemarksChange = new SetTableRemarksChange();
if (control.getIncludeCatalog()) {
setRemarksChange.setCatalogName(view.getSchema().getCatalogName());
}
if (control.getIncludeSchema()) {
setRemarksChange.setSchemaName(view.getSchema().getName());
}
setRemarksChange.setTableName(view.getName());
setRemarksChange.setRemarks(view.getRemarks());
changes.add(setRemarksChange);
}
return changes.toArray(new Change[changes.size()]);
}
Aggregations