use of liquibase.change.core.DropUniqueConstraintChange in project liquibase by liquibase.
the class UnexpectedUniqueConstraintChangeGenerator method fixUnexpected.
@Override
public Change[] fixUnexpected(DatabaseObject unexpectedObject, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) {
UniqueConstraint uc = (UniqueConstraint) unexpectedObject;
if (uc.getTable() == null) {
return null;
}
DropUniqueConstraintChange change = new DropUniqueConstraintChange();
change.setTableName(uc.getTable().getName());
if (control.getIncludeCatalog()) {
change.setCatalogName(uc.getTable().getSchema().getCatalogName());
}
if (control.getIncludeSchema()) {
change.setSchemaName(uc.getTable().getSchema().getName());
}
change.setConstraintName(uc.getName());
Index backingIndex = uc.getBackingIndex();
// if (backingIndex == null) {
// Index exampleIndex = new Index().setTable(uc.getTable());
// for (String col : uc.getColumns()) {
// exampleIndex.getColumns().add(col);
// }
// control.setAlreadyHandledUnexpected(exampleIndex);
// } else {
control.setAlreadyHandledUnexpected(backingIndex);
return new Change[] { change };
}
use of liquibase.change.core.DropUniqueConstraintChange in project liquibase by liquibase.
the class ChangedUniqueConstraintChangeGenerator method fixChanged.
@Override
public Change[] fixChanged(DatabaseObject changedObject, ObjectDifferences differences, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) {
List<Change> returnList = new ArrayList<Change>();
UniqueConstraint uniqueConstraint = (UniqueConstraint) changedObject;
DropUniqueConstraintChange dropUniqueConstraintChange = createDropUniqueConstraintChange();
dropUniqueConstraintChange.setTableName(uniqueConstraint.getTable().getName());
dropUniqueConstraintChange.setConstraintName(uniqueConstraint.getName());
AddUniqueConstraintChange addUniqueConstraintChange = createAddUniqueConstraintChange();
addUniqueConstraintChange.setConstraintName(uniqueConstraint.getName());
addUniqueConstraintChange.setTableName(uniqueConstraint.getTable().getName());
addUniqueConstraintChange.setColumnNames(uniqueConstraint.getColumnNames());
returnList.add(dropUniqueConstraintChange);
if (control.getIncludeCatalog()) {
dropUniqueConstraintChange.setCatalogName(uniqueConstraint.getSchema().getCatalogName());
addUniqueConstraintChange.setCatalogName(uniqueConstraint.getSchema().getCatalogName());
}
if (control.getIncludeSchema()) {
dropUniqueConstraintChange.setSchemaName(uniqueConstraint.getSchema().getName());
addUniqueConstraintChange.setSchemaName(uniqueConstraint.getSchema().getName());
}
Index backingIndex = uniqueConstraint.getBackingIndex();
if (comparisonDatabase instanceof OracleDatabase) {
if (backingIndex != null && backingIndex.getName() != null) {
Change[] missingIndexChanges = ChangeGeneratorFactory.getInstance().fixMissing(backingIndex, control, referenceDatabase, comparisonDatabase);
if (missingIndexChanges != null) {
returnList.addAll(Arrays.asList(missingIndexChanges));
}
addUniqueConstraintChange.setForIndexName(backingIndex.getName());
Schema schema = backingIndex.getSchema();
if (schema != null) {
if (control.getIncludeCatalog()) {
addUniqueConstraintChange.setForIndexCatalogName(schema.getCatalogName());
}
if (control.getIncludeSchema()) {
addUniqueConstraintChange.setForIndexSchemaName(schema.getName());
}
}
}
}
control.setAlreadyHandledChanged(backingIndex);
returnList.add(addUniqueConstraintChange);
return returnList.toArray(new Change[returnList.size()]);
}
Aggregations