Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

CORE-1279: Generate Rollback Script File With SpringLiquibase #120

Merged
merged 1 commit into from about 1 year ago

2 participants

James Carman Nathan Voxland
James Carman

This change adds a "rollbackFile" property to SpringLiquibase. If this property is set, it will attempt to write a "future rollback SQL" file to the file prior to executing the migration.

Nathan Voxland nvoxland merged commit 552501a into from March 17, 2013
Nathan Voxland nvoxland closed this March 17, 2013
Nathan Voxland
Owner

Seems helpful. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Mar 12, 2013
James Carman Adding rollback file support. 054fe68
This page is out of date. Refresh to see the latest.
21  liquibase-core/src/main/java/liquibase/integration/spring/SpringLiquibase.java
... ...
@@ -1,8 +1,6 @@
1 1
 package liquibase.integration.spring;
2 2
 
3  
-import java.io.FileNotFoundException;
4  
-import java.io.IOException;
5  
-import java.io.InputStream;
  3
+import java.io.*;
6 4
 import java.net.URL;
7 5
 import java.sql.Connection;
8 6
 import java.sql.SQLException;
@@ -139,6 +137,8 @@ public ClassLoader toClassLoader() {
139 137
 
140 138
     private boolean shouldRun = true;
141 139
 
  140
+    private File rollbackFile;
  141
+
142 142
     public SpringLiquibase() {
143 143
         super();
144 144
     }
@@ -251,6 +251,7 @@ public void afterPropertiesSet() throws LiquibaseException {
251 251
         try {
252 252
             c = getDataSource().getConnection();
253 253
             liquibase = createLiquibase(c);
  254
+            generateRollbackFile(liquibase);
254 255
             performUpdate(liquibase);
255 256
         } catch (SQLException e) {
256 257
             throw new DatabaseException(e);
@@ -267,6 +268,16 @@ public void afterPropertiesSet() throws LiquibaseException {
267 268
 
268 269
     }
269 270
 
  271
+    private void generateRollbackFile(Liquibase liquibase) throws LiquibaseException {
  272
+        if(rollbackFile != null) {
  273
+            try {
  274
+                liquibase.futureRollbackSQL(getContexts(), new FileWriter(rollbackFile));
  275
+            } catch (IOException e) {
  276
+                throw new LiquibaseException("Unable to generate rollback file.", e);
  277
+            }
  278
+        }
  279
+    }
  280
+
270 281
     protected void performUpdate(Liquibase liquibase) throws LiquibaseException {
271 282
         liquibase.update(getContexts());
272 283
     }
@@ -336,6 +347,10 @@ public ResourceLoader getResourceLoader() {
336 347
         return resourceLoader;
337 348
     }
338 349
 
  350
+    public void setRollbackFile(File rollbackFile) {
  351
+        this.rollbackFile = rollbackFile;
  352
+    }
  353
+
339 354
     @Override
340 355
     public String toString() {
341 356
         return getClass().getName()+"("+this.getResourceLoader().toString()+")";
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.