Search in sources :

Example 6 with DiffResult

use of liquibase.diff.DiffResult 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)

Example 7 with DiffResult

use of liquibase.diff.DiffResult in project liquibase by liquibase.

the class DiffCommand method run.

@Override
protected CommandResult run() throws Exception {
    DiffResult diffResult = createDiffResult();
    new DiffToReport(diffResult, outputStream).print();
    return new CommandResult("OK");
}
Also used : DiffToReport(liquibase.diff.output.report.DiffToReport) DiffResult(liquibase.diff.DiffResult) CommandResult(liquibase.command.CommandResult)

Example 8 with DiffResult

use of liquibase.diff.DiffResult in project liquibase by liquibase.

the class DiffToChangeLogCommand method run.

@Override
protected CommandResult run() throws Exception {
    DiffResult diffResult = createDiffResult();
    PrintStream outputStream = this.getOutputStream();
    if (outputStream == null) {
        outputStream = System.out;
    }
    if (StringUtils.trimToNull(changeLogFile) == null) {
        createDiffToChangeLogObject(diffResult).print(outputStream);
    } else {
        createDiffToChangeLogObject(diffResult).print(changeLogFile);
    }
    return new CommandResult("OK");
}
Also used : PrintStream(java.io.PrintStream) DiffResult(liquibase.diff.DiffResult) CommandResult(liquibase.command.CommandResult)

Example 9 with DiffResult

use of liquibase.diff.DiffResult in project liquibase by liquibase.

the class GenerateChangeLogCommand method run.

@Override
protected CommandResult run() throws Exception {
    DiffResult diffResult = createDiffResult();
    DiffToChangeLog changeLogWriter = new DiffToChangeLog(diffResult, getDiffOutputControl());
    changeLogWriter.setChangeSetAuthor(author);
    changeLogWriter.setChangeSetContext(context);
    changeLogWriter.setChangeSetPath(getChangeLogFile());
    if (StringUtils.trimToNull(getChangeLogFile()) != null) {
        changeLogWriter.print(getChangeLogFile());
    } else {
        PrintStream outputStream = getOutputStream();
        if (outputStream == null) {
            outputStream = System.out;
        }
        changeLogWriter.print(outputStream);
    }
    return new CommandResult("OK");
}
Also used : PrintStream(java.io.PrintStream) DiffToChangeLog(liquibase.diff.output.changelog.DiffToChangeLog) DiffResult(liquibase.diff.DiffResult) CommandResult(liquibase.command.CommandResult)

Example 10 with DiffResult

use of liquibase.diff.DiffResult in project liquibase by liquibase.

the class DiffToChangeLogTest method getOrderedOutputTypes_isConsistant.

@Test
public void getOrderedOutputTypes_isConsistant() 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()));
        }
    }
}
Also used : MySQLDatabase(liquibase.database.core.MySQLDatabase) EmptyDatabaseSnapshot(liquibase.snapshot.EmptyDatabaseSnapshot) CompareControl(liquibase.diff.compare.CompareControl) DatabaseObject(liquibase.structure.DatabaseObject) DiffResult(liquibase.diff.DiffResult) Test(org.junit.Test)

Aggregations

DiffResult (liquibase.diff.DiffResult)16 CompareControl (liquibase.diff.compare.CompareControl)11 Test (org.junit.Test)8 DiffToChangeLog (liquibase.diff.output.changelog.DiffToChangeLog)7 DiffOutputControl (liquibase.diff.output.DiffOutputControl)6 DiffToReport (liquibase.diff.output.report.DiffToReport)6 DatabaseSnapshot (liquibase.snapshot.DatabaseSnapshot)5 SnapshotControl (liquibase.snapshot.SnapshotControl)5 PrintStream (java.io.PrintStream)4 Liquibase (liquibase.Liquibase)3 CommandResult (liquibase.command.CommandResult)3 DatabaseException (liquibase.exception.DatabaseException)3 DatabaseObject (liquibase.structure.DatabaseObject)3 IOException (java.io.IOException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 CatalogAndSchema (liquibase.CatalogAndSchema)2 AbstractIntegrationTest (liquibase.dbtest.AbstractIntegrationTest)2 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)2 ValidationFailedException (liquibase.exception.ValidationFailedException)2 EmptyDatabaseSnapshot (liquibase.snapshot.EmptyDatabaseSnapshot)2