Search in sources :

Example 46 with ChangeSet

use of liquibase.changelog.ChangeSet in project liquibase by liquibase.

the class AbstractIntegrationTest method generateChangeLog_noChanges.

@Test
public void generateChangeLog_noChanges() throws Exception {
    if (database == null) {
        return;
    }
    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(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)

Example 47 with ChangeSet

use of liquibase.changelog.ChangeSet in project iaf by ibissource.

the class LiquibaseImpl method update.

public void update() {
    List<String> changes = new ArrayList<String>();
    try {
        List<ChangeSet> changeSets = liquibase.listUnrunChangeSets(contexts, labelExpression);
        for (ChangeSet changeSet : changeSets) {
            changes.add("LiquiBase applying change [" + changeSet.getId() + ":" + changeSet.getAuthor() + "] description [" + changeSet.getDescription() + "]");
        }
        if (changeSets.size() > 0) {
            liquibase.update(contexts);
            ChangeSet lastChange = changeSets.get(changeSets.size() - 1);
            String tag = lastChange.getId() + ":" + lastChange.getAuthor();
            tag(tag);
            if (changes.size() > 1) {
                log("LiquiBase applied [" + changes.size() + "] change(s) and added tag [" + tag + "]");
            } else {
                for (String change : changes) {
                    log(change + " tag [" + tag + "]");
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        String errorMsg = "Error running LiquiBase update. Failed to execute [" + changes.size() + "] change(s): ";
        errorMsg += e.getMessage();
        ConfigurationWarnings.getInstance().add(log, errorMsg, e);
    }
}
Also used : ArrayList(java.util.ArrayList) ChangeSet(liquibase.changelog.ChangeSet) LiquibaseException(liquibase.exception.LiquibaseException)

Example 48 with ChangeSet

use of liquibase.changelog.ChangeSet in project minijax by minijax.

the class LiquibaseHelper method validateDatabaseState.

/**
 * Validates that the database is in a good state.
 *
 * @param database The database.
 * @param fileName The change log file name.
 * @param resourceAccessor The change log file loader.
 */
private void validateDatabaseState(final Database database) throws LiquibaseException {
    final Liquibase liquibase = getLiquibase(database);
    // all contexts
    final Contexts contexts = new Contexts();
    // no filters
    final LabelExpression labels = new LabelExpression();
    final List<ChangeSet> unrunChangeSets = liquibase.listUnrunChangeSets(contexts, labels);
    if (!unrunChangeSets.isEmpty()) {
        throw new IllegalStateException("Unrun change sets!  Please migrate the database first");
    }
}
Also used : Liquibase(liquibase.Liquibase) LabelExpression(liquibase.LabelExpression) Contexts(liquibase.Contexts) ChangeSet(liquibase.changelog.ChangeSet)

Example 49 with ChangeSet

use of liquibase.changelog.ChangeSet in project minijax by minijax.

the class LiquibaseHelperTest method testNotIgnoreEmptyChangeSet.

@Test
public void testNotIgnoreEmptyChangeSet() {
    final ChangeSet changeSet = new ChangeSet(null);
    assertFalse(LiquibaseHelper.isIgnoredChangeSet(changeSet));
}
Also used : ChangeSet(liquibase.changelog.ChangeSet) Test(org.junit.Test)

Example 50 with ChangeSet

use of liquibase.changelog.ChangeSet in project minijax by minijax.

the class LiquibaseHelperTest method testNotIgnoreDropOtherTable.

@Test
public void testNotIgnoreDropOtherTable() {
    final DropTableChange change = new DropTableChange();
    change.setTableName("foo");
    final ChangeSet changeSet = new ChangeSet(null);
    changeSet.addChange(change);
    assertFalse(LiquibaseHelper.isIgnoredChangeSet(changeSet));
}
Also used : DropTableChange(liquibase.change.core.DropTableChange) ChangeSet(liquibase.changelog.ChangeSet) Test(org.junit.Test)

Aggregations

ChangeSet (liquibase.changelog.ChangeSet)75 Test (org.junit.Test)41 RanChangeSet (liquibase.changelog.RanChangeSet)13 Contexts (liquibase.Contexts)12 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)11 Database (liquibase.database.Database)11 ArrayList (java.util.ArrayList)10 Liquibase (liquibase.Liquibase)10 Change (liquibase.change.Change)9 LiquibaseException (liquibase.exception.LiquibaseException)9 DiffOutputControl (liquibase.diff.output.DiffOutputControl)7 DiffToChangeLog (liquibase.diff.output.changelog.DiffToChangeLog)7 IOException (java.io.IOException)6 ObjectQuotingStrategy (liquibase.database.ObjectQuotingStrategy)6 DiffResult (liquibase.diff.DiffResult)6 CompareControl (liquibase.diff.compare.CompareControl)6 LabelExpression (liquibase.LabelExpression)5 Sql (liquibase.sql.Sql)5 SqlStatement (liquibase.statement.SqlStatement)5 MarkChangeSetRanStatement (liquibase.statement.core.MarkChangeSetRanStatement)5