use of liquibase.change.Change in project liquibase by liquibase.
the class DBDocVisitor method visit.
@Override
public void visit(ChangeSet changeSet, DatabaseChangeLog databaseChangeLog, Database database, Set<ChangeSetFilterResult> filterResults) throws LiquibaseException {
ChangeSet.RunStatus runStatus = this.database.getRunStatus(changeSet);
if (rootChangeLogName == null) {
rootChangeLogName = changeSet.getFilePath();
}
if (rootChangeLog == null) {
this.rootChangeLog = databaseChangeLog;
}
if (!changesByAuthor.containsKey(changeSet.getAuthor())) {
changesByAuthor.put(changeSet.getAuthor(), new ArrayList<Change>());
}
if (!changesToRunByAuthor.containsKey(changeSet.getAuthor())) {
changesToRunByAuthor.put(changeSet.getAuthor(), new ArrayList<Change>());
}
boolean toRun = runStatus.equals(ChangeSet.RunStatus.NOT_RAN) || runStatus.equals(ChangeSet.RunStatus.RUN_AGAIN);
for (Change change : changeSet.getChanges()) {
if (toRun) {
changesToRunByAuthor.get(changeSet.getAuthor()).add(change);
changesToRun.add(change);
} else {
changesByAuthor.get(changeSet.getAuthor()).add(change);
recentChanges.add(0, change);
}
}
ChangeLogInfo changeLogInfo = new ChangeLogInfo(changeSet.getChangeLog().getLogicalFilePath(), changeSet.getChangeLog().getPhysicalFilePath());
if (!changeLogs.contains(changeLogInfo)) {
changeLogs.add(changeLogInfo);
}
for (Change change : changeSet.getChanges()) {
Set<DatabaseObject> affectedDatabaseObjects = change.getAffectedDatabaseObjects(database);
if (affectedDatabaseObjects != null) {
for (DatabaseObject dbObject : affectedDatabaseObjects) {
if (toRun) {
if (!changesToRunByObject.containsKey(dbObject)) {
changesToRunByObject.put(dbObject, new ArrayList<Change>());
}
changesToRunByObject.get(dbObject).add(change);
} else {
if (!changesByObject.containsKey(dbObject)) {
changesByObject.put(dbObject, new ArrayList<Change>());
}
changesByObject.get(dbObject).add(change);
}
}
}
}
}
use of liquibase.change.Change in project liquibase by liquibase.
the class MissingUniqueConstraintChangeGenerator method fixMissing.
@Override
public Change[] fixMissing(DatabaseObject missingObject, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) {
List<Change> returnList = new ArrayList<Change>();
UniqueConstraint uc = (UniqueConstraint) missingObject;
if (uc.getTable() == null) {
return null;
}
AddUniqueConstraintChange change = new AddUniqueConstraintChange();
change.setTableName(uc.getTable().getName());
if (uc.getBackingIndex() != null && control.getIncludeTablespace()) {
change.setTablespace(uc.getBackingIndex().getTablespace());
}
if (control.getIncludeCatalog()) {
change.setCatalogName(uc.getTable().getSchema().getCatalogName());
}
if (control.getIncludeSchema()) {
change.setSchemaName(uc.getTable().getSchema().getName());
}
change.setConstraintName(uc.getName());
change.setColumnNames(uc.getColumnNames());
change.setDeferrable(uc.isDeferrable() ? Boolean.TRUE : null);
change.setInitiallyDeferred(uc.isInitiallyDeferred() ? Boolean.TRUE : null);
change.setDisabled(uc.isDisabled() ? Boolean.TRUE : null);
if (referenceDatabase instanceof MSSQLDatabase) {
change.setClustered(uc.isClustered() ? Boolean.TRUE : null);
}
if (comparisonDatabase instanceof OracleDatabase) {
Index backingIndex = uc.getBackingIndex();
if (backingIndex != null && backingIndex.getName() != null) {
Change[] changes = ChangeGeneratorFactory.getInstance().fixMissing(backingIndex, control, referenceDatabase, comparisonDatabase);
if (changes != null) {
returnList.addAll(Arrays.asList(changes));
change.setForIndexName(backingIndex.getName());
Schema schema = backingIndex.getSchema();
if (schema != null) {
if (control.getIncludeCatalog()) {
change.setForIndexCatalogName(schema.getCatalogName());
}
if (control.getIncludeSchema()) {
change.setForIndexSchemaName(schema.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.setAlreadyHandledMissing(exampleIndex);
// } else {
control.setAlreadyHandledMissing(backingIndex);
// }
returnList.add(change);
return returnList.toArray(new Change[returnList.size()]);
}
use of liquibase.change.Change in project liquibase by liquibase.
the class MissingViewChangeGenerator method fixMissing.
@Override
public Change[] fixMissing(DatabaseObject missingObject, DiffOutputControl control, Database referenceDatabase, final Database comparisonDatabase, ChangeGeneratorChain chain) {
View view = (View) missingObject;
CreateViewChange change = createViewChange();
change.setViewName(view.getName());
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().size() > 0) {
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 + " (" + StringUtils.join(view.getColumns(), ", ", new StringUtils.StringUtilsFormatter() {
@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());
}
return new Change[] { change };
}
use of liquibase.change.Change in project liquibase by liquibase.
the class UnexpectedColumnChangeGenerator method fixUnexpected.
@Override
public Change[] fixUnexpected(DatabaseObject unexpectedObject, DiffOutputControl control, Database referenceDatabase, Database comparisonDatabase, ChangeGeneratorChain chain) {
Column column = (Column) unexpectedObject;
if (column.getComputed() != null && column.getComputed()) {
//not really a column to drop, probably part of an index or something
return null;
}
if (column.getRelation() instanceof View) {
return null;
}
if (column.getRelation().getSnapshotId() == null) {
//not an actual table, maybe an alias, maybe in a different schema. Don't fix it.
return null;
}
DropColumnChange change = new DropColumnChange();
change.setTableName(column.getRelation().getName());
if (control.getIncludeCatalog()) {
change.setCatalogName(column.getRelation().getSchema().getCatalogName());
}
if (control.getIncludeSchema()) {
change.setSchemaName(column.getRelation().getSchema().getName());
}
change.setColumnName(column.getName());
return new Change[] { change };
}
use of liquibase.change.Change 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 };
}
Aggregations