001 package liquibase.integration.ant;
002
003 import liquibase.Liquibase;
004 import liquibase.util.ui.UIFactory;
005 import org.apache.tools.ant.BuildException;
006
007 /**
008 * Ant task for migrating a database forward testing rollback.
009 */
010 public class DatabaseUpdateTestingRollbackTask extends BaseLiquibaseTask {
011 private boolean dropFirst = false;
012
013 public boolean isDropFirst() {
014 return dropFirst;
015 }
016
017 public void setDropFirst(boolean dropFirst) {
018 this.dropFirst = dropFirst;
019 }
020
021 @Override
022 public void execute() throws BuildException {
023 if (!shouldRun()) {
024 return;
025 }
026
027 super.execute();
028
029 Liquibase liquibase = null;
030 try {
031 liquibase = createLiquibase();
032
033 if (isPromptOnNonLocalDatabase() && !liquibase.isSafeToRunMigration()
034 && UIFactory.getInstance().getFacade().promptForNonLocalDatabase(liquibase.getDatabase())) {
035 throw new BuildException("Chose not to run against non-production database");
036 }
037
038 if (isDropFirst()) {
039 liquibase.dropAll();
040 }
041
042 liquibase.updateTestingRollback(getContexts());
043
044 } catch (Exception e) {
045 throw new BuildException(e);
046 } finally {
047 closeDatabase(liquibase);
048 }
049 }
050 }