Permalink
Browse files

Added support for futureRollbackCountSQL

  • Loading branch information...
nvoxland committed Apr 27, 2012
1 parent cf0af03 commit c065a26032c332b8765333ecd8812f9da53b37fc
@@ -431,6 +431,10 @@ public void markNextChangeSetRan(String contexts) throws LiquibaseException {
}
public void futureRollbackSQL(String contexts, Writer output) throws LiquibaseException {
+ futureRollbackSQL(null, contexts, output);
+ }
+
+ public void futureRollbackSQL(Integer count, String contexts, Writer output) throws LiquibaseException {
changeLogParameters.setContexts(StringUtils.splitAndTrim(contexts, ","));
LoggingExecutor outputTemplate = new LoggingExecutor(ExecutorService.getInstance().getExecutor(database), output, database);
@@ -447,10 +451,31 @@ public void futureRollbackSQL(String contexts, Writer output) throws LiquibaseEx
checkDatabaseChangeLogTable(false, changeLog, contexts);
changeLog.validate(database, contexts);
- ChangeLogIterator logIterator = new ChangeLogIterator(changeLog,
- new NotRanChangeSetFilter(database.getRanChangeSetList()),
- new ContextChangeSetFilter(contexts),
- new DbmsChangeSetFilter(database));
+ ChangeLogIterator logIterator;
+ if (count == null) {
+ logIterator = new ChangeLogIterator(changeLog,
+ new NotRanChangeSetFilter(database.getRanChangeSetList()),
+ new ContextChangeSetFilter(contexts),
+ new DbmsChangeSetFilter(database));
+ } else {
+ ChangeLogIterator forwardIterator = new ChangeLogIterator(changeLog,
+ new NotRanChangeSetFilter(database.getRanChangeSetList()),
+ new ContextChangeSetFilter(contexts),
+ new DbmsChangeSetFilter(database),
+ new CountChangeSetFilter(count));
+ final ListVisitor listVisitor = new ListVisitor();
+ forwardIterator.run(listVisitor, database);
+
+ logIterator = new ChangeLogIterator(changeLog,
+ new NotRanChangeSetFilter(database.getRanChangeSetList()),
+ new ContextChangeSetFilter(contexts),
+ new DbmsChangeSetFilter(database),
+ new ChangeSetFilter() {
+ public boolean accepts(ChangeSet changeSet) {
+ return listVisitor.getSeenChangeSets().contains(changeSet);
+ }
+ });
+ }
logIterator.run(new RollbackVisitor(database), database);
} finally {
@@ -316,6 +316,7 @@ private boolean isCommand(String arg) {
|| "rollbackToDateSQL".equalsIgnoreCase(arg)
|| "rollbackCountSQL".equalsIgnoreCase(arg)
|| "futureRollbackSQL".equalsIgnoreCase(arg)
+ || "futureRollbackCountSQL".equalsIgnoreCase(arg)
|| "updateTestingRollback".equalsIgnoreCase(arg)
|| "tag".equalsIgnoreCase(arg)
|| "listLocks".equalsIgnoreCase(arg)
@@ -435,6 +436,9 @@ protected void printHelp(PrintStream stream) {
stream.println(" futureRollbackSQL Writes SQL to roll back the database to the ");
stream.println(" current state after the changes in the ");
stream.println(" changeslog have been applied");
+ stream.println(" futureRollbackSQL <value> Writes SQL to roll back the database to the ");
+ stream.println(" current state after <value> changes in the ");
+ stream.println(" changeslog have been applied");
stream.println(" updateTestingRollback Updates database, then rolls back changes before");
stream.println(" updating again. Useful for testing");
stream.println(" rollback support");
@@ -864,6 +868,12 @@ protected void doMigration() throws Exception {
liquibase.rollback(Integer.parseInt(commandParams.iterator().next()), contexts, getOutputWriter());
} else if ("futureRollbackSQL".equalsIgnoreCase(command)) {
liquibase.futureRollbackSQL(contexts, getOutputWriter());
+ } else if ("futureRollbackCountSQL".equalsIgnoreCase(command)) {
+ if (commandParams == null || commandParams.size() == 0) {
+ throw new CommandLineParsingException("futureRollbackCountSQL requires a rollback count");
+ }
+
+ liquibase.futureRollbackSQL(Integer.parseInt(commandParams.iterator().next()), contexts, getOutputWriter());
} else if ("updateTestingRollback".equalsIgnoreCase(command)) {
liquibase.updateTestingRollback(contexts);
} else {
@@ -10,7 +10,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/filtered-resources" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/.settings" />
- <excludeFolder url="file://$MODULE_DIR$/src/test/resources/hibernate" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
@@ -2,21 +2,21 @@
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="Osmorc" name="OSGi">
- <configuration manifestGenerationMode="Manually" manifestLocation="src/main/resources/META-INF/MANIFEST.MF" jarfileLocation="liquibase-osgi-2.0.4-SNAPSHOT.jar" outputPathType="CompilerOutputPath" bndFileLocation="" bundlorFileLocation="" bundleActivator="liquibase.osgi.LiquibaseActivator" bundleSymbolicName="org.liquibase.osgi" bundleVersion="2.0.4.SNAPSHOT" ignoreFilePattern="" useProjectDefaultManifestFileLocation="false" alwaysRebuildBundleJAR="false" doNotSynchronizeWithMaven="false">
+ <configuration manifestGenerationMode="Manually" manifestLocation="src/main/resources/META-INF/MANIFEST.MF" jarfileLocation="liquibase-osgi-2.0.5-SNAPSHOT.jar" outputPathType="CompilerOutputPath" bndFileLocation="" bundlorFileLocation="" bundleActivator="liquibase.osgi.LiquibaseActivator" bundleSymbolicName="org.liquibase.osgi" bundleVersion="2.0.5.SNAPSHOT" ignoreFilePattern="" useProjectDefaultManifestFileLocation="false" alwaysRebuildBundleJAR="false" doNotSynchronizeWithMaven="false">
<additionalProperties>
<property key="Bundle-Description" value="Liquibase is a tool for managing and executing database changes." />
<property key="Bundle-Vendor" value="Liquibase.org" />
<property key="Bundle-DocURL" value="http://www.liquibase.org" />
<property key="Bundle-Name" value="Liquibase with OSGI Support" />
- <property key="Export-Package" value="liquibase.*;version=&quot;2.0.4-SNAPSHOT&quot;" />
- <property key="Import-Package" value="liquibase.*;version=&quot;2.0.4-SNAPSHOT&quot;,org.slf4j;version=&quot;[1.5,2.0)&quot;,javax.*;resolution:=optional,org.apache.tools.ant.*;resolution:=optional,org.springframework.*;resolution:=optional,org.w3c.*;resolution:=optional,org.xml.*;resolution:=optional,org.osgi.framework.*;resolution:=optional" />
+ <property key="Export-Package" value="liquibase.*;version=&quot;2.0.5-SNAPSHOT&quot;" />
+ <property key="Import-Package" value="liquibase.*;version=&quot;2.0.5-SNAPSHOT&quot;,org.slf4j;version=&quot;[1.5,2.0)&quot;,javax.*;resolution:=optional,org.apache.tools.ant.*;resolution:=optional,org.springframework.*;resolution:=optional,org.w3c.*;resolution:=optional,org.xml.*;resolution:=optional,org.osgi.framework.*;resolution:=optional" />
<property key="Embed-Dependency" value="*;scope=compile|runtime;type=!pom;inline=false;artifactId=!slf4j-api" />
<property key="Embed-Transitive" value="true" />
<property key="DynamicImport-Package" value="net.sf.cglib.*" />
<property key="-include" value="src/main/resources/META-INF/MANIFEST.MF" />
- <property key="Bundle-ClassPath" value=".,liquibase-core-2.0.4-SNAPSHOT.jar" />
- <property key="Include-Resource" value="liquibase-core-2.0.4-SNAPSHOT.jar=$MODULE_DIR$/../liquibase-core/pom.xml" />
- <property key="Embedded-Artifacts" value="liquibase-core-2.0.4-SNAPSHOT.jar;g=&quot;org.liquibase&quot;;a=&quot;liquibase-core&quot;;v=&quot;2.0.4-SNAPSHOT&quot;" />
+ <property key="Bundle-ClassPath" value=".,liquibase-core-2.0.5-SNAPSHOT.jar" />
+ <property key="Include-Resource" value="liquibase-core-2.0.5-SNAPSHOT.jar=$MODULE_DIR$/../liquibase-core/pom.xml" />
+ <property key="Embedded-Artifacts" value="liquibase-core-2.0.5-SNAPSHOT.jar;g=&quot;org.liquibase&quot;;a=&quot;liquibase-core&quot;;v=&quot;2.0.5-SNAPSHOT&quot;" />
</additionalProperties>
<additionalJARContents />
</configuration>
@@ -32,8 +32,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="module" module-name="liquibase-core" />
- <orderEntry type="library" scope="PROVIDED" name="Maven: org.osgi:org.osgi.core:4.1.0" level="project" />
</component>
</module>
View
@@ -11,6 +11,14 @@
<properties />
</buildFile>
</component>
+ <component name="ArtifactManager">
+ <artifact type="jar" build-on-make="true" name="liquibase">
+ <output-path>$PROJECT_DIR$/out/artifacts/liquibase</output-path>
+ <root id="archive" name="liquibase.jar">
+ <element id="module-output" name="liquibase-core" />
+ </root>
+ </artifact>
+ </component>
<component name="BuildJarProjectSettings">
<option name="BUILD_JARS_ON_MAKE" value="false" />
</component>
@@ -10,7 +10,7 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
- <orderEntry type="module" module-name="liquibase-core" exported="" />
+ <orderEntry type="module" module-name="liquibase-core" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.8.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.easymock:easymockclassextension:2.2" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.easymock:easymock:2.2" level="project" />

0 comments on commit c065a26

Please sign in to comment.