Search in sources :

Example 21 with CompareControl

use of liquibase.diff.compare.CompareControl in project liquibase by liquibase.

the class CommandLineUtils method doGenerateChangeLog.

public static void doGenerateChangeLog(String changeLogFile, Database originalDatabase, CatalogAndSchema[] schemas, String snapshotTypes, String author, String context, String dataDir, DiffOutputControl diffOutputControl) throws IOException, ParserConfigurationException, LiquibaseException {
    CompareControl.SchemaComparison[] comparisons = new CompareControl.SchemaComparison[schemas.length];
    int i = 0;
    for (CatalogAndSchema schema : schemas) {
        comparisons[i++] = new CompareControl.SchemaComparison(schema, schema);
    }
    CompareControl compareControl = new CompareControl(comparisons, snapshotTypes);
    diffOutputControl.setDataDir(dataDir);
    CommandScope command = new CommandScope("internalGenerateChangeLog");
    command.addArgumentValue(InternalGenerateChangelogCommandStep.REFERENCE_DATABASE_ARG, originalDatabase).addArgumentValue(InternalGenerateChangelogCommandStep.SNAPSHOT_TYPES_ARG, InternalGenerateChangelogCommandStep.parseSnapshotTypes(snapshotTypes)).addArgumentValue(InternalGenerateChangelogCommandStep.COMPARE_CONTROL_ARG, compareControl).addArgumentValue(InternalGenerateChangelogCommandStep.CHANGELOG_FILE_ARG, changeLogFile).addArgumentValue(InternalGenerateChangelogCommandStep.DIFF_OUTPUT_CONTROL_ARG, diffOutputControl).addArgumentValue(InternalGenerateChangelogCommandStep.AUTHOR_ARG, author).addArgumentValue(InternalGenerateChangelogCommandStep.CONTEXT_ARG, context);
    command.setOutput(System.out);
    try {
        command.execute();
    } catch (CommandExecutionException e) {
        throw new LiquibaseException(e);
    }
}
Also used : CompareControl(liquibase.diff.compare.CompareControl) CommandExecutionException(liquibase.exception.CommandExecutionException) LiquibaseException(liquibase.exception.LiquibaseException) CatalogAndSchema(liquibase.CatalogAndSchema) CommandScope(liquibase.command.CommandScope)

Example 22 with CompareControl

use of liquibase.diff.compare.CompareControl in project liquibase by liquibase.

the class CommandLineUtils method doDiffToChangeLog.

public static void doDiffToChangeLog(String changeLogFile, Database referenceDatabase, Database targetDatabase, DiffOutputControl diffOutputControl, ObjectChangeFilter objectChangeFilter, String snapshotTypes, CompareControl.SchemaComparison[] schemaComparisons) throws LiquibaseException, IOException, ParserConfigurationException {
    CommandScope command = new CommandScope("internalDiffChangeLog");
    command.addArgumentValue(InternalDiffChangelogCommandStep.REFERENCE_DATABASE_ARG, referenceDatabase).addArgumentValue(InternalDiffChangelogCommandStep.TARGET_DATABASE_ARG, targetDatabase).addArgumentValue(InternalDiffChangelogCommandStep.SNAPSHOT_TYPES_ARG, InternalDiffChangelogCommandStep.parseSnapshotTypes(snapshotTypes)).addArgumentValue(InternalDiffChangelogCommandStep.COMPARE_CONTROL_ARG, new CompareControl(schemaComparisons, snapshotTypes)).addArgumentValue(InternalDiffChangelogCommandStep.OBJECT_CHANGE_FILTER_ARG, objectChangeFilter).addArgumentValue(InternalDiffChangelogCommandStep.CHANGELOG_FILE_ARG, changeLogFile).addArgumentValue(InternalDiffChangelogCommandStep.DIFF_OUTPUT_CONTROL_ARG, diffOutputControl);
    command.setOutput(System.out);
    try {
        command.execute();
    } catch (CommandExecutionException e) {
        throw new LiquibaseException(e);
    }
}
Also used : CompareControl(liquibase.diff.compare.CompareControl) CommandExecutionException(liquibase.exception.CommandExecutionException) LiquibaseException(liquibase.exception.LiquibaseException) CommandScope(liquibase.command.CommandScope)

Example 23 with CompareControl

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

Example 24 with CompareControl

use of liquibase.diff.compare.CompareControl 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()));
        }
    }
}
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)

Example 25 with CompareControl

use of liquibase.diff.compare.CompareControl in project liquibase by liquibase.

the class AbstractIntegrationTest method testGenerateChangeLogWithNoChanges.

@Test
public void testGenerateChangeLogWithNoChanges() throws Exception {
    assumeNotNull(this.getDatabase());
    runCompleteChangeLog();
    DiffResult diffResult = DiffGeneratorFactory.getInstance().compare(database, database, new CompareControl());
    DiffToChangeLog changeLogWriter = new DiffToChangeLog(diffResult, new DiffOutputControl(false, false, false, null));
    List<ChangeSet> changeSets = changeLogWriter.generateChangeSets();
    assertEquals("generating two change logs without any changes in between should result in an empty generated " + "differential change set.", 0, changeSets.size());
}
Also used : CompareControl(liquibase.diff.compare.CompareControl) DiffOutputControl(liquibase.diff.output.DiffOutputControl) DiffToChangeLog(liquibase.diff.output.changelog.DiffToChangeLog) DiffResult(liquibase.diff.DiffResult) ChangeSet(liquibase.changelog.ChangeSet) Test(org.junit.Test)

Aggregations

CompareControl (liquibase.diff.compare.CompareControl)30 DiffResult (liquibase.diff.DiffResult)18 Test (org.junit.Test)14 DiffOutputControl (liquibase.diff.output.DiffOutputControl)10 DiffToChangeLog (liquibase.diff.output.changelog.DiffToChangeLog)10 CatalogAndSchema (liquibase.CatalogAndSchema)8 SnapshotControl (liquibase.snapshot.SnapshotControl)8 ChangeSet (liquibase.changelog.ChangeSet)7 DatabaseSnapshot (liquibase.snapshot.DatabaseSnapshot)7 DatabaseObject (liquibase.structure.DatabaseObject)7 LiquibaseException (liquibase.exception.LiquibaseException)6 Database (liquibase.database.Database)5 ObjectQuotingStrategy (liquibase.database.ObjectQuotingStrategy)4 AbstractIntegrationTest (liquibase.dbtest.AbstractIntegrationTest)4 DiffToReport (liquibase.diff.output.report.DiffToReport)4 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)4 EmptyDatabaseSnapshot (liquibase.snapshot.EmptyDatabaseSnapshot)4 File (java.io.File)3 Liquibase (liquibase.Liquibase)3 CommandScope (liquibase.command.CommandScope)3