Search in sources :

Example 1 with RollbackContainer

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

the class ExampleExecutor method validate.

/**
 * Validate whether the change set can be executed by this Executor
 *
 * @param   changeSet The change set to validate
 * @return  boolean   True if all changes can be executed by the custom Executor
 *                    False if any change cannot be executed
 */
@Override
public ValidationErrors validate(ChangeSet changeSet) {
    // 
    if (changeSet.getRunWith() == null || changeSet.getRunWith().isEmpty()) {
        return new ValidationErrors();
    }
    // 
    // License check
    // 
    ValidationErrors validationErrors = new ValidationErrors();
    // 
    // Verify for go-forward and rollback changes
    // 
    List<Change> changes = changeSet.getChanges();
    for (Change change : changes) {
        validateChange(changeSet, validationErrors, change, "");
    }
    if (changeSet.getRollback() != null) {
        RollbackContainer container = changeSet.getRollback();
        List<Change> rollbackChanges = container.getChanges();
        for (Change change : rollbackChanges) {
            Scope.getCurrentScope().getLog(getClass()).info("Validating rollback change " + change.getDescription());
            validateChange(changeSet, validationErrors, change, "");
        }
    }
    return validationErrors;
}
Also used : RollbackContainer(liquibase.changelog.RollbackContainer) ValidationErrors(liquibase.exception.ValidationErrors) Change(liquibase.change.Change)

Example 2 with RollbackContainer

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

the class RollbackVisitor method checkForEmptyRollbackFile.

private void checkForEmptyRollbackFile(ChangeSet changeSet) {
    RollbackContainer container = changeSet.getRollback();
    List<Change> changes = container.getChanges();
    if (changes.isEmpty()) {
        return;
    }
    for (Change change : changes) {
        if (!(change instanceof SQLFileChange)) {
            continue;
        }
        String sql = ((SQLFileChange) change).getSql();
        if (sql.length() == 0) {
            Scope.getCurrentScope().getLog(getClass()).info("\nNo rollback logic defined in empty rollback script. Changesets have been removed from\n" + "the DATABASECHANGELOG table but no other logic was performed.");
        }
    }
}
Also used : RollbackContainer(liquibase.changelog.RollbackContainer) SQLFileChange(liquibase.change.core.SQLFileChange) Change(liquibase.change.Change) SQLFileChange(liquibase.change.core.SQLFileChange)

Aggregations

Change (liquibase.change.Change)2 RollbackContainer (liquibase.changelog.RollbackContainer)2 SQLFileChange (liquibase.change.core.SQLFileChange)1 ValidationErrors (liquibase.exception.ValidationErrors)1