use of liquibase.diff.compare.CompareControl in project liquibase by liquibase.
the class Liquibase method generateChangeLog.
public void generateChangeLog(CatalogAndSchema catalogAndSchema, DiffToChangeLog changeLogWriter, PrintStream outputStream, ChangeLogSerializer changeLogSerializer, Class<? extends DatabaseObject>... snapshotTypes) throws DatabaseException, IOException, ParserConfigurationException {
Set<Class<? extends DatabaseObject>> finalCompareTypes = null;
if (snapshotTypes != null && snapshotTypes.length > 0) {
finalCompareTypes = new HashSet<Class<? extends DatabaseObject>>(Arrays.asList(snapshotTypes));
}
SnapshotControl snapshotControl = new SnapshotControl(this.getDatabase(), snapshotTypes);
CompareControl compareControl = new CompareControl(new CompareControl.SchemaComparison[] { new CompareControl.SchemaComparison(catalogAndSchema, catalogAndSchema) }, finalCompareTypes);
// compareControl.addStatusListener(new OutDiffStatusListener());
DatabaseSnapshot originalDatabaseSnapshot = null;
try {
originalDatabaseSnapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(compareControl.getSchemas(CompareControl.DatabaseRole.REFERENCE), getDatabase(), snapshotControl);
DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(originalDatabaseSnapshot, SnapshotGeneratorFactory.getInstance().createSnapshot(compareControl.getSchemas(CompareControl.DatabaseRole.REFERENCE), null, snapshotControl), compareControl);
changeLogWriter.setDiffResult(diffResult);
if (changeLogSerializer != null) {
changeLogWriter.print(outputStream, changeLogSerializer);
} else {
changeLogWriter.print(outputStream);
}
} catch (InvalidExampleException e) {
throw new UnexpectedLiquibaseException(e);
}
}
use of liquibase.diff.compare.CompareControl in project liquibase by liquibase.
the class H2IntegrationTest method diffToChangeLog.
@Test
public void diffToChangeLog() throws Exception {
if (getDatabase() == null) {
return;
}
runCompleteChangeLog();
DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(getDatabase(), null, new CompareControl());
new DiffToChangeLog(diffResult, new DiffOutputControl(true, true, true, null)).print(System.out);
}
use of liquibase.diff.compare.CompareControl in project liquibase by liquibase.
the class H2IntegrationTest method diffToPrintStream.
@Test
public void diffToPrintStream() throws Exception {
if (getDatabase() == null) {
return;
}
runCompleteChangeLog();
DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(getDatabase(), null, new CompareControl());
new DiffToReport(diffResult, System.out).print();
}
use of liquibase.diff.compare.CompareControl in project liquibase by liquibase.
the class AbstractIntegrationTest method testDiff.
@Test
public void testDiff() throws Exception {
if (database == null) {
return;
}
runCompleteChangeLog();
CompareControl compareControl = new CompareControl();
//database returns different data even if the same
compareControl.addSuppressedField(Column.class, "defaultValue");
//database returns different data even if the same
compareControl.addSuppressedField(Column.class, "autoIncrementInformation");
DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(database, database, compareControl);
try {
assertTrue(diffResult.areEqual());
} catch (AssertionError e) {
new DiffToReport(diffResult, System.err).print();
throw e;
}
}
use of liquibase.diff.compare.CompareControl in project dropwizard by dropwizard.
the class DbDumpCommand method generateChangeLog.
private void generateChangeLog(final Database database, final CatalogAndSchema catalogAndSchema, final DiffToChangeLog changeLogWriter, PrintStream outputStream, final Set<Class<? extends DatabaseObject>> compareTypes) throws DatabaseException, IOException, ParserConfigurationException {
@SuppressWarnings({ "unchecked", "rawtypes" }) final SnapshotControl snapshotControl = new SnapshotControl(database, compareTypes.toArray(new Class[compareTypes.size()]));
final CompareControl compareControl = new CompareControl(new CompareControl.SchemaComparison[] { new CompareControl.SchemaComparison(catalogAndSchema, catalogAndSchema) }, compareTypes);
final CatalogAndSchema[] compareControlSchemas = compareControl.getSchemas(CompareControl.DatabaseRole.REFERENCE);
try {
final DatabaseSnapshot referenceSnapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(compareControlSchemas, database, snapshotControl);
final DatabaseSnapshot comparisonSnapshot = SnapshotGeneratorFactory.getInstance().createSnapshot(compareControlSchemas, null, snapshotControl);
final DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(referenceSnapshot, comparisonSnapshot, compareControl);
changeLogWriter.setDiffResult(diffResult);
changeLogWriter.print(outputStream);
} catch (InvalidExampleException e) {
throw new UnexpectedLiquibaseException(e);
}
}
Aggregations