use of liquibase.change.core.DropForeignKeyConstraintChange in project liquibase by liquibase.
the class UnexpectedForeignKeyChangeGenerator method fixUnexpected.
@Override
public Change[] fixUnexpected(DatabaseObject unexpectedObject, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) {
ForeignKey fk = (ForeignKey) unexpectedObject;
DropForeignKeyConstraintChange change = new DropForeignKeyConstraintChange();
change.setConstraintName(fk.getName());
change.setBaseTableName(fk.getForeignKeyTable().getName());
if (control.getIncludeCatalog()) {
change.setBaseTableCatalogName(fk.getForeignKeyTable().getSchema().getCatalogName());
}
if (control.getIncludeSchema()) {
change.setBaseTableSchemaName(fk.getForeignKeyTable().getSchema().getName());
}
Index backingIndex = fk.getBackingIndex();
// if (backingIndex == null) {
// Index exampleIndex = new Index().setTable(fk.getForeignKeyTable());
// for (String col : fk.getForeignKeyColumns().split("\\s*,\\s*")) {
// exampleIndex.getColumns().add(col);
// }
// control.setAlreadyHandledUnexpected(exampleIndex);
// } else {
control.setAlreadyHandledUnexpected(backingIndex);
return new Change[] { change };
}
use of liquibase.change.core.DropForeignKeyConstraintChange in project liquibase by liquibase.
the class ChangedForeignKeyChangeGenerator method fixChanged.
@Override
public Change[] fixChanged(DatabaseObject changedObject, ObjectDifferences differences, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) {
ForeignKey fk = (ForeignKey) changedObject;
StringUtil.StringUtilFormatter formatter = new StringUtil.StringUtilFormatter<Column>() {
@Override
public String toString(Column obj) {
return obj.toString(false);
}
};
DropForeignKeyConstraintChange dropFkChange = new DropForeignKeyConstraintChange();
dropFkChange.setConstraintName(fk.getName());
dropFkChange.setBaseTableName(fk.getForeignKeyTable().getName());
AddForeignKeyConstraintChange addFkChange = new AddForeignKeyConstraintChange();
addFkChange.setConstraintName(fk.getName());
addFkChange.setBaseTableName(fk.getForeignKeyTable().getName());
addFkChange.setBaseColumnNames(StringUtil.join(fk.getForeignKeyColumns(), ",", formatter));
addFkChange.setReferencedTableName(fk.getPrimaryKeyTable().getName());
addFkChange.setReferencedColumnNames(StringUtil.join(fk.getPrimaryKeyColumns(), ",", formatter));
addFkChange.setOnDelete(fk.getDeleteRule());
addFkChange.setOnUpdate(fk.getUpdateRule());
if (control.getIncludeCatalog()) {
dropFkChange.setBaseTableCatalogName(fk.getForeignKeyTable().getSchema().getCatalogName());
addFkChange.setBaseTableCatalogName(fk.getForeignKeyTable().getSchema().getCatalogName());
addFkChange.setReferencedTableCatalogName(fk.getPrimaryKeyTable().getSchema().getCatalogName());
}
if (control.getIncludeSchema()) {
dropFkChange.setBaseTableSchemaName(fk.getForeignKeyTable().getSchema().getName());
addFkChange.setBaseTableSchemaName(fk.getForeignKeyTable().getSchema().getName());
addFkChange.setReferencedTableSchemaName(fk.getPrimaryKeyTable().getSchema().getName());
}
if (fk.getBackingIndex() != null) {
control.setAlreadyHandledChanged(fk.getBackingIndex());
}
return new Change[] { dropFkChange, addFkChange };
}
Aggregations