@Override
public Change[] fixMissing(DatabaseObject missingObject, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) {
ForeignKey fk = (ForeignKey) missingObject;
AddForeignKeyConstraintChange change = new AddForeignKeyConstraintChange();
change.setConstraintName(fk.getName());
change.setReferencedTableName(fk.getPrimaryKeyTable().getName());
if (!((ForeignKey) missingObject).getPrimaryKeyTable().getSchema().equals(((ForeignKey) missingObject).getForeignKeyTable().getSchema()) || control.getIncludeCatalog()) {
change.setReferencedTableCatalogName(fk.getPrimaryKeyTable().getSchema().getCatalogName());
}
if (!((ForeignKey) missingObject).getPrimaryKeyTable().getSchema().equals(((ForeignKey) missingObject).getForeignKeyTable().getSchema()) || control.getIncludeSchema()) {
change.setReferencedTableSchemaName(fk.getPrimaryKeyTable().getSchema().getName());
}
change.setReferencedColumnNames(StringUtils.join(fk.getPrimaryKeyColumns(), ",", new StringUtils.StringUtilsFormatter<Column>() {
@Override
public String toString(Column obj) {
return obj.getName();
}
}));
change.setBaseTableName(fk.getForeignKeyTable().getName());
if (control.getIncludeCatalog()) {
change.setBaseTableCatalogName(fk.getForeignKeyTable().getSchema().getCatalogName());
}
if (control.getIncludeSchema()) {
change.setBaseTableSchemaName(fk.getForeignKeyTable().getSchema().getName());
}
change.setBaseColumnNames(StringUtils.join(fk.getForeignKeyColumns(), ",", new StringUtils.StringUtilsFormatter<Column>() {
@Override
public String toString(Column obj) {
return obj.getName();
}
}));
change.setDeferrable(fk.isDeferrable());
change.setInitiallyDeferred(fk.isInitiallyDeferred());
change.setOnUpdate(fk.getUpdateRule());
change.setOnDelete(fk.getDeleteRule());
Index backingIndex = fk.getBackingIndex();
// if (backingIndex == null) {
// Index exampleIndex = new Index().setTable(fk.getForeignKeyTable());
// for (String col : fk.getForeignKeyColumns().split("\\s*,\\s*")) {