Search in sources :

Example 11 with RanChangeSet

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

the class ValidatingVisitor method findChangeSet.

private RanChangeSet findChangeSet(ChangeSet changeSet) {
    RanChangeSet result = ranIndex.get(changeSet.toString(false));
    if (result == null) {
        for (RanChangeSet ranChangeSet : ranIndex.values()) {
            if (ranChangeSet.getId().equalsIgnoreCase(changeSet.getId())) {
                if (ranChangeSet.getAuthor().equalsIgnoreCase(changeSet.getAuthor())) {
                    String changeSetPath = normalizePath(changeSet.getFilePath());
                    String ranChangeSetPath = normalizePath(ranChangeSet.getChangeLog());
                    if (ranChangeSetPath.equalsIgnoreCase(changeSetPath) || ranChangeSetPath.endsWith(changeSetPath) || changeSetPath.endsWith(ranChangeSetPath)) {
                        result = ranChangeSet;
                    }
                }
            }
        }
    }
    return result;
}
Also used : RanChangeSet(liquibase.changelog.RanChangeSet)

Example 12 with RanChangeSet

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

the class ValidatingVisitor method visit.

@Override
public void visit(ChangeSet changeSet, DatabaseChangeLog databaseChangeLog, Database database, Set<ChangeSetFilterResult> filterResults) throws LiquibaseException {
    RanChangeSet ranChangeSet = findChangeSet(changeSet);
    boolean ran = ranChangeSet != null;
    boolean shouldValidate = !ran || changeSet.shouldRunOnChange() || changeSet.shouldAlwaysRun();
    for (Change change : changeSet.getChanges()) {
        try {
            change.finishInitialization();
        } catch (SetupException se) {
            setupExceptions.add(se);
        }
        if (shouldValidate) {
            warnings.addAll(change.warn(database));
            try {
                ValidationErrors foundErrors = change.validate(database);
                if (foundErrors != null && foundErrors.hasErrors()) {
                    if (changeSet.getOnValidationFail().equals(ChangeSet.ValidationFailOption.MARK_RAN)) {
                        LogFactory.getLogger().info("Skipping changeSet " + changeSet + " due to validation error(s): " + StringUtils.join(foundErrors.getErrorMessages(), ", "));
                        changeSet.setValidationFailed(true);
                    } else {
                        validationErrors.addAll(foundErrors, changeSet);
                    }
                }
            } catch (Throwable e) {
                changeValidationExceptions.add(e);
            }
        }
    }
    if (ranChangeSet != null) {
        if (!changeSet.isCheckSumValid(ranChangeSet.getLastCheckSum())) {
            if (!changeSet.shouldRunOnChange()) {
                invalidMD5Sums.add(changeSet.toString(false) + " was: " + ranChangeSet.getLastCheckSum().toString() + " but is now: " + changeSet.generateCheckSum().toString());
            }
        }
    }
    String changeSetString = changeSet.toString(false);
    if (seenChangeSets.contains(changeSetString)) {
        duplicateChangeSets.add(changeSet);
    } else {
        seenChangeSets.add(changeSetString);
    }
}
Also used : Change(liquibase.change.Change) RanChangeSet(liquibase.changelog.RanChangeSet)

Example 13 with RanChangeSet

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

the class ValidatingVisitorPreConditionsTest method testPreConditionsForOracleOnMSSQLWithPreconditionTag.

/**
     * Test only the precondition tag with a precondition requiring oracle but
     * giving a MSSQL database.
     */
@Test
public void testPreConditionsForOracleOnMSSQLWithPreconditionTag() {
    // create the pre condition
    PreconditionContainer preCondition = new PreconditionContainer();
    preCondition.setOnFail(PreconditionContainer.FailOption.MARK_RAN.toString());
    DBMSPrecondition dbmsPrecondition = new DBMSPrecondition();
    dbmsPrecondition.setType("oracle");
    preCondition.addNestedPrecondition(dbmsPrecondition);
    changeSet1.setPreconditions(preCondition);
    MSSQLDatabase mssqlDb = new MSSQLDatabase() {

        @Override
        public List<RanChangeSet> getRanChangeSetList() throws DatabaseException {
            return new ArrayList<RanChangeSet>();
        }

        @Override
        public void rollback() throws DatabaseException {
        //super.rollback();
        }
    };
    boolean failedExceptionThrown = false;
    boolean errorExceptionThrown = false;
    try {
        preCondition.check(mssqlDb, changeLog, changeSet1);
    } catch (PreconditionFailedException ex) {
        failedExceptionThrown = true;
    } catch (PreconditionErrorException ex) {
        errorExceptionThrown = true;
    }
    assertTrue(failedExceptionThrown);
    assertFalse(errorExceptionThrown);
}
Also used : PreconditionContainer(liquibase.precondition.core.PreconditionContainer) DBMSPrecondition(liquibase.precondition.core.DBMSPrecondition) ArrayList(java.util.ArrayList) PreconditionFailedException(liquibase.exception.PreconditionFailedException) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) RanChangeSet(liquibase.changelog.RanChangeSet) PreconditionErrorException(liquibase.exception.PreconditionErrorException) Test(org.junit.Test)

Example 14 with RanChangeSet

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

the class ValidatingVisitorPreConditionsTest method testPreConditionsForOracleOnMSSQLWithChangeLog.

/**
     * Test the same precondition from a changelog with mssql database, this
     * should not fail on the validation but just mark is as handled.
     */
@Test
public void testPreConditionsForOracleOnMSSQLWithChangeLog() {
    // create the pre condition
    PreconditionContainer preCondition = new PreconditionContainer();
    preCondition.setOnFail(PreconditionContainer.FailOption.MARK_RAN.toString());
    DBMSPrecondition dbmsPrecondition = new DBMSPrecondition();
    dbmsPrecondition.setType("oracle");
    preCondition.addNestedPrecondition(dbmsPrecondition);
    changeSet1.setPreconditions(preCondition);
    MSSQLDatabase mssqlDb = new MSSQLDatabase() {

        @Override
        public List<RanChangeSet> getRanChangeSetList() throws DatabaseException {
            return new ArrayList<RanChangeSet>();
        }

        @Override
        public void rollback() throws DatabaseException {
        //super.rollback();
        }
    };
    String[] empty = {};
    boolean exceptionThrown = false;
    try {
        // call the validate which gives the error
        changeLog.validate(mssqlDb, empty);
    } catch (LiquibaseException ex) {
        System.out.println(ex.getMessage());
        exceptionThrown = true;
    }
    assertFalse(exceptionThrown);
}
Also used : PreconditionContainer(liquibase.precondition.core.PreconditionContainer) DBMSPrecondition(liquibase.precondition.core.DBMSPrecondition) ArrayList(java.util.ArrayList) MSSQLDatabase(liquibase.database.core.MSSQLDatabase) LiquibaseException(liquibase.exception.LiquibaseException) RanChangeSet(liquibase.changelog.RanChangeSet) Test(org.junit.Test)

Example 15 with RanChangeSet

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

the class ValidatingVisitorTest method visit_validateError.

@Test
public void visit_validateError() throws Exception {
    changeSet1.addChange(new CreateTableChange() {

        @Override
        public ValidationErrors validate(Database database) {
            ValidationErrors changeValidationErrors = new ValidationErrors();
            changeValidationErrors.addError("Test message");
            return changeValidationErrors;
        }
    });
    List<RanChangeSet> ran = new ArrayList<RanChangeSet>();
    ValidatingVisitor handler = new ValidatingVisitor(ran);
    handler.visit(changeSet1, new DatabaseChangeLog(), null, null);
    assertEquals(1, handler.getValidationErrors().getErrorMessages().size());
    assertTrue(handler.getValidationErrors().getErrorMessages().get(0).startsWith("Test message"));
    assertFalse(handler.validationPassed());
}
Also used : ValidationErrors(liquibase.exception.ValidationErrors) CreateTableChange(liquibase.change.core.CreateTableChange) MockDatabase(liquibase.sdk.database.MockDatabase) Database(liquibase.database.Database) ArrayList(java.util.ArrayList) DatabaseChangeLog(liquibase.changelog.DatabaseChangeLog) RanChangeSet(liquibase.changelog.RanChangeSet) Test(org.junit.Test)

Aggregations

RanChangeSet (liquibase.changelog.RanChangeSet)16 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)8 ChangeSet (liquibase.changelog.ChangeSet)5 DatabaseChangeLog (liquibase.changelog.DatabaseChangeLog)5 Date (java.util.Date)4 CreateTableChange (liquibase.change.core.CreateTableChange)4 DBMSPrecondition (liquibase.precondition.core.DBMSPrecondition)3 PreconditionContainer (liquibase.precondition.core.PreconditionContainer)3 MockDatabase (liquibase.sdk.database.MockDatabase)3 Database (liquibase.database.Database)2 MSSQLDatabase (liquibase.database.core.MSSQLDatabase)2 LiquibaseException (liquibase.exception.LiquibaseException)2 PreconditionErrorException (liquibase.exception.PreconditionErrorException)2 PreconditionFailedException (liquibase.exception.PreconditionFailedException)2 ValidationErrors (liquibase.exception.ValidationErrors)2 Change (liquibase.change.Change)1 ColumnConfig (liquibase.change.ColumnConfig)1 ObjectQuotingStrategy (liquibase.database.ObjectQuotingStrategy)1 OracleDatabase (liquibase.database.core.OracleDatabase)1