Francis Raj
Francis Raj

Reputation: 107

How to generate a liquibase rollback script using spring boot?

I have a simple changeset for creating a table and the rollback is drop'ing the same. I want a rollback script to be generated each time springboot is started. Any help?. many thanks.

Upvotes: 2

Views: 3683

Answers (2)

Francis Raj
Francis Raj

Reputation: 107

liquibase.rollback-file is the field which can be used to generate a roll-back script by spring-boot. Which we need to run manually to rollback.

Upvotes: 2

Fana Sithole
Fana Sithole

Reputation: 340

It sounds like you this in place:

<changeSet id="new_table_change" author="the_man">
   <createTable tableName="new_table">
       <column name="id" type="int"/>
   </createTable>
   <rollback>
       <dropTable tableName="new_table"/>
   </rollback>
</changeSet>

With this in place, you can always, as part of your pipeline, you can generate the rollback script with the following command:

mvn liquibase:futureRollbackSQL

For your current problem, if your environment allows, you can do the following:

  • Shutdown your application
  • Rollback using one of the command options: rollback to a Date (mvn liquibase:rollbackToDateSQL <date_time>) or number of steps (mvn liquibase:rollbackCountSQL <no_of_steps>)
  • Run the mvn liquibase:futureRollbackSQL and save the results
  • Apply your changes again by starting your application again

Upvotes: 0

Related Questions