Reputation: 2053
I am trying out Liquibase in view of trying to automate Database Deployments and get some structure around Database changes.
Here is my Changeset which i wanted to evaluate for auto rollbacks. Now, i am trying to introduce an error in the foreign key constraint
and was expecting that the rollback statements
run after the error and it deletes the column from the customer
table as well.
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
<preConditions>
<dbms type="mysql" />
</preConditions>
<changeSet id="002" author="Hrishi" failOnError="true"
runInTransaction="true">
<preConditions onError="HALT" onFail="HALT"
onFailMessage="The table gender doesnt exist. Precondition not met.">
<not>
<columnExists tableName="customer" columnName="gender_id" />
</not>
<and>
<not>
<foreignKeyConstraintExists foreignKeyName="fk_gender_customer"/>
</not>
</and>
</preConditions>
<addColumn tableName="customer" schemaName="sakila">
<column name="gender_id" type="smallint(1)" />
</addColumn>
<addForeignKeyConstraint constraintName="fk_gender_customer"
referencedTableName="gender" baseColumnNames="gender_id"
baseTableName="customer" referencedColumnNames="invoking_an_error" />
<rollback>
<dropColumn tableName="customer" columnName="gender_id" />
<dropForeignKeyConstraint baseTableName="customer"
constraintName="fk_gender_customer" />
</rollback>
</changeSet>
What really though does happen is that there is no entry in the DATABASECHANGELOG
table. Which i expected, but then the column in the customer
table still exists.
I did look at the help on the addColumn
url on liquibase documentation and MySQL is supported.
http://www.liquibase.org/documentation/changes/add_column.html
Is my understanding correct that it should autorollback all the statements in the changeset?
EDIT : I think the problem in this specific case is that the ALTER table is a DDL statement. From the documentation of MySQL cannot-roll-back.
Upvotes: 1
Views: 793
Reputation: 9016
I'm not sure of the command you issued, but the changes listed in the <rollback>
section of the changeset do not happen automatically when an error happens. When an error happens, liquibase tries to roll back the database transaction, but if some things have already been committed, you can get into an inconsistent state. The <rollback>
tag is there so that you can manually roll back changes by using the liquibase rollback command.
Upvotes: 0