Search in sources :

Example 6 with CompareControl

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);
    }
}
Also used : InvalidExampleException(liquibase.snapshot.InvalidExampleException) DatabaseObject(liquibase.structure.DatabaseObject) CompareControl(liquibase.diff.compare.CompareControl) DiffResult(liquibase.diff.DiffResult) SnapshotControl(liquibase.snapshot.SnapshotControl) DatabaseSnapshot(liquibase.snapshot.DatabaseSnapshot) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 7 with CompareControl

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);
}
Also used : CompareControl(liquibase.diff.compare.CompareControl) DiffOutputControl(liquibase.diff.output.DiffOutputControl) DiffToChangeLog(liquibase.diff.output.changelog.DiffToChangeLog) DiffResult(liquibase.diff.DiffResult) AbstractIntegrationTest(liquibase.dbtest.AbstractIntegrationTest) Test(org.junit.Test)

Example 8 with CompareControl

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();
}
Also used : DiffToReport(liquibase.diff.output.report.DiffToReport) CompareControl(liquibase.diff.compare.CompareControl) DiffResult(liquibase.diff.DiffResult) AbstractIntegrationTest(liquibase.dbtest.AbstractIntegrationTest) Test(org.junit.Test)

Example 9 with CompareControl

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;
    }
}
Also used : DiffToReport(liquibase.diff.output.report.DiffToReport) CompareControl(liquibase.diff.compare.CompareControl) DiffResult(liquibase.diff.DiffResult) Test(org.junit.Test)

Example 10 with CompareControl

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);
    }
}
Also used : InvalidExampleException(liquibase.snapshot.InvalidExampleException) CompareControl(liquibase.diff.compare.CompareControl) DiffResult(liquibase.diff.DiffResult) CatalogAndSchema(liquibase.CatalogAndSchema) SnapshotControl(liquibase.snapshot.SnapshotControl) DatabaseSnapshot(liquibase.snapshot.DatabaseSnapshot) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Aggregations

CompareControl (liquibase.diff.compare.CompareControl)17 DiffResult (liquibase.diff.DiffResult)11 Test (org.junit.Test)8 CatalogAndSchema (liquibase.CatalogAndSchema)6 DatabaseSnapshot (liquibase.snapshot.DatabaseSnapshot)6 SnapshotControl (liquibase.snapshot.SnapshotControl)6 DiffOutputControl (liquibase.diff.output.DiffOutputControl)5 DiffToChangeLog (liquibase.diff.output.changelog.DiffToChangeLog)5 Liquibase (liquibase.Liquibase)4 DiffToReport (liquibase.diff.output.report.DiffToReport)4 CommandExecutionException (liquibase.command.CommandExecutionException)3 DatabaseObject (liquibase.structure.DatabaseObject)3 ObjectQuotingStrategy (liquibase.database.ObjectQuotingStrategy)2 AbstractIntegrationTest (liquibase.dbtest.AbstractIntegrationTest)2 LiquibaseException (liquibase.exception.LiquibaseException)2 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)2 ValidationFailedException (liquibase.exception.ValidationFailedException)2 EmptyDatabaseSnapshot (liquibase.snapshot.EmptyDatabaseSnapshot)2 InvalidExampleException (liquibase.snapshot.InvalidExampleException)2 Change (liquibase.change.Change)1