Reputation: 83
My group is considering using Liquibase within our Spring Boot startup. I'm concerned about accidentally rolling back schema changes. My scenario works like this:
Is liquibase smart enough to NOT do an implicit rollback when the user doesn't explicitly run a rollback request? Or is there some configuration that must be made to prevent my scenario?
Upvotes: 2
Views: 343
Reputation: 7330
To answer your question - No, Liquibase will not roll back your schema by it's own will.
Let's review case #4.
When Spring-Boot will be started with obsolete version of changeLogs, Liquibase will try to execute only the given set (the obsolete one) of changeLogs (which haven't been run already).
Liquibase is interested only in the given set of changeSets in the given set of changeLogs. Everything else in the schema will be non of Liquibase's concern, e.g. if some_new_table
exists in the db schema and it's not described in the given set of changeSets, this table will not be dropped.
BUT
in order for this to work you have to keep in mind the following:
When Liquibase executes a changeSet, it stores some metadata about the execution in databasechangelog
table. Liquibase does it in order to keep an eye on changeSet's integrity and in order not to execute it againg if it has already been executed
you have to write preConditions
for your changeSets to ensure that the changeSet will not be executed if it should not be executed. For example:
<changeSet id="foo" author="bar">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="some_new_table"/>
</not>
</preConditions>
<comment>Create some_new_table table</comment>
<createTable tableName="some_new_table">
<!-- your columns here -->
</createTable>
</changeSet>
This way Liquibase will check if some_new_table
exists before trying to create it.
Upvotes: 1