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;
}
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);
}
}
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);
}
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);
}
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());
}
Aggregations