use of liquibase.structure.DatabaseObject in project liquibase by liquibase.
the class DiffToChangeLogTest method getOrderedOutputTypes_hasDependencies.
@Test
public void getOrderedOutputTypes_hasDependencies() throws Exception {
MySQLDatabase database = new MySQLDatabase();
Class<? extends DatabaseObject>[] typesArray = new Class[5];
typesArray[0] = Schema.class;
typesArray[1] = View.class;
typesArray[2] = Catalog.class;
typesArray[3] = Table.class;
typesArray[4] = Column.class;
SnapshotControl control = new SnapshotControl(database, typesArray);
EmptyDatabaseSnapshot emptyDatabaseSnapshot = new EmptyDatabaseSnapshot(database, control);
DiffToChangeLog obj = new DiffToChangeLog(new DiffResult(emptyDatabaseSnapshot, emptyDatabaseSnapshot, new CompareControl()), null);
for (Class<? extends ChangeGenerator> type : new Class[] { UnexpectedObjectChangeGenerator.class, MissingObjectChangeGenerator.class, ChangedObjectChangeGenerator.class }) {
List<Class<? extends DatabaseObject>> orderedOutputTypes = obj.getOrderedOutputTypes(type);
assertThat("There should be some types", orderedOutputTypes, hasSize(greaterThan(5)));
}
List<Class<? extends DatabaseObject>> unexpectedOrderedOutputTypes = obj.getOrderedOutputTypes(UnexpectedObjectChangeGenerator.class);
assertThat("There should be some types", unexpectedOrderedOutputTypes, hasSize(7));
List<Class<? extends DatabaseObject>> missingOrderedOutputTypes = obj.getOrderedOutputTypes(MissingObjectChangeGenerator.class);
assertThat("There should be some types", missingOrderedOutputTypes, hasSize(6));
List<Class<? extends DatabaseObject>> changedOrderedOutputTypes = obj.getOrderedOutputTypes(ChangedObjectChangeGenerator.class);
assertThat("There should be some types", changedOrderedOutputTypes, hasSize(6));
}
use of liquibase.structure.DatabaseObject in project liquibase by liquibase.
the class DiffToChangeLogTest method getOrderedOutputTypes_isConsistent.
@Test
public void getOrderedOutputTypes_isConsistent() throws Exception {
MySQLDatabase database = new MySQLDatabase();
DiffToChangeLog obj = new DiffToChangeLog(new DiffResult(new EmptyDatabaseSnapshot(database), new EmptyDatabaseSnapshot(database), new CompareControl()), null);
for (Class<? extends ChangeGenerator> type : new Class[] { UnexpectedObjectChangeGenerator.class, MissingObjectChangeGenerator.class, ChangedObjectChangeGenerator.class }) {
List<Class<? extends DatabaseObject>> orderedOutputTypes = obj.getOrderedOutputTypes(type);
for (int i = 0; i < 50; i++) {
assertThat("Error checking " + type.getName(), orderedOutputTypes, contains(obj.getOrderedOutputTypes(type).toArray()));
}
}
}
use of liquibase.structure.DatabaseObject in project liquibase by liquibase.
the class StandardChangeLogHistoryService method destroy.
@Override
public void destroy() throws DatabaseException {
Database database = getDatabase();
try {
//
// This code now uses the ChangeGeneratorFactory to
// allow extension code to be called in order to
// delete the changelog table.
//
// To implement the extension, you will need to override:
// DropTableStatement
// DropTableChange
// DropTableGenerator
//
//
DatabaseObject example = new Table().setName(database.getDatabaseChangeLogTableName()).setSchema(database.getLiquibaseCatalogName(), database.getLiquibaseSchemaName());
if (SnapshotGeneratorFactory.getInstance().has(example, database)) {
DatabaseObject table = SnapshotGeneratorFactory.getInstance().createSnapshot(example, database);
DiffOutputControl diffOutputControl = new DiffOutputControl(true, true, false, null);
Change[] change = ChangeGeneratorFactory.getInstance().fixUnexpected(table, diffOutputControl, database, database);
SqlStatement[] sqlStatement = change[0].generateStatements(database);
Scope.getCurrentScope().getSingleton(ExecutorService.class).getExecutor("jdbc", database).execute(sqlStatement[0]);
}
reset();
} catch (InvalidExampleException e) {
throw new UnexpectedLiquibaseException(e);
}
}
use of liquibase.structure.DatabaseObject in project liquibase by liquibase.
the class StandardObjectChangeFilter method parseFilter.
protected void parseFilter(String filter) {
filter = StringUtil.trimToNull(filter);
if (filter == null) {
return;
}
// first, split the string on commas to get the subfilters
for (String subfilter : filter.split("\\s*,\\s*")) {
// each subfilter can be either "objecttype:regex" or just "regex", so split on colon to decide
String[] split = subfilter.split(":");
if (split.length == 1) {
filters.add(new Filter(null, Pattern.compile(split[0])));
} else {
String className = StringUtil.upperCaseFirst(split[0]);
className = "liquibase.structure.core." + className;
try {
Class<DatabaseObject> clazz = (Class<DatabaseObject>) Class.forName(className);
filters.add(new Filter(clazz, Pattern.compile(split[1])));
catalogOrSchemaFilter |= "Catalog".equals(className) || "Schema".equals(className);
} catch (ClassNotFoundException e) {
throw new UnexpectedLiquibaseException(e);
}
}
}
}
use of liquibase.structure.DatabaseObject in project liquibase by liquibase.
the class UniqueConstraintComparator method findDifferences.
@Override
public ObjectDifferences findDifferences(DatabaseObject databaseObject1, DatabaseObject databaseObject2, Database accordingTo, CompareControl compareControl, DatabaseObjectComparatorChain chain, Set<String> exclude) {
exclude.add("name");
exclude.add("columns");
exclude.add("backingIndex");
ObjectDifferences differences = chain.findDifferences(databaseObject1, databaseObject2, accordingTo, compareControl, exclude);
differences.compare("columns", databaseObject1, databaseObject2, new ObjectDifferences.CompareFunction() {
@Override
public boolean areEqual(Object referenceValue, Object compareToValue) {
List<Column> referenceList = (List) referenceValue;
List<Column> compareList = (List) compareToValue;
if (referenceList.size() != compareList.size()) {
return false;
}
for (int i = 0; i < referenceList.size(); i++) {
if (!StringUtil.trimToEmpty((referenceList.get(i)).getName()).equalsIgnoreCase(StringUtil.trimToEmpty(compareList.get(i).getName()))) {
return false;
}
}
return true;
}
});
differences.compare("backingIndex", databaseObject1, databaseObject2, new ObjectDifferences.StandardCompareFunction(chain.getSchemaComparisons(), accordingTo));
return differences;
}
Aggregations