In 2.0 a really nice freature was added called LiquiBased Formatted SQL. See this link for info http://blog.liquibase.org/2010/05/liquibase-formatted-sql.html.
When I try to add a rollback command to my script which in my case is dropping a view that was created LiquiBase throws an error. Here is my script.
--liquibase formatted sql
--changeset PeterPan:REQ111111
CREATE VIEW all_employees AS
SELECT *
FROM employee;
--rollback
DROP VIEW all_employees;
--rollback
I also tried this too
--liquibase formatted sql
--changeset PeterPan:REQ111111
CREATE VIEW all_employees AS
SELECT *
FROM employee;
--rollback
DROP VIEW all_employees;
Here is my command line input and the output I get. Note I did the update which succeeds and then a rollback which is what fails. Also keep in mind the view gets dropped just the script throws an exception. If I remove my view from the build and run the same commands both update and rollback finish with success.
C:\>liquibase --driver=org.postgresql.Driver --classpath="C:/Program Files/Java/jdk1.6.0_23/lib/postgresql-9.0-801.jdbc4.jar" --url="jdbc:postgresql:/
/localhost:5432/test_db_build" --changeLogFile=C:/DbSource/Common/00_main_changelog.xml --username=postgres --password=password update
INFO 3/3/11 10:05 AM:liquibase: Successfully acquired change log lock
INFO 3/3/11 10:05 AM:liquibase: Reading from databasechangelog
INFO 3/3/11 10:05 AM:liquibase: Reading from databasechangelog
INFO 3/3/11 10:05 AM:liquibase: ChangeSet C:/DbSource/Tables/0001_CreateTableEmployee.xml::1::PeterPan ran successfully in 78ms
INFO 3/3/11 10:05 AM:liquibase: ChangeSet C:/DbSource/Tables/0002_CreateSchema-test.xml::2::PeterPan ran successfully in 15ms
INFO 3/3/11 10:05 AM:liquibase: ChangeSet C:/DbSource/Tables/0003_CreateTable-junk.xml::4::PeterPan ran successfully in 31ms
INFO 3/3/11 10:05 AM:liquibase: ChangeSet C:/DbSource/Tables/0004_CreateTable-test.fun_log.xml::4::PeterPan ran successfully in 156ms
INFO 3/3/11 10:05 AM:liquibase: ChangeSet C:/DbSource/Views/001_all_employees.sql::REQ111111::PeterPan ran successfully in 15ms
INFO 3/3/11 10:05 AM:liquibase: ChangeSet C:/DbSource/DML/0001_InsertInto-public.employee.xml::4::PeterPan ran successfully in 16ms
INFO 3/3/11 10:05 AM:liquibase: ChangeSet C:/DbSource/DML/0002_Truncate-public.employee.xml::4::PeterPan ran successfully in 282ms
INFO 3/3/11 10:05 AM:liquibase: ChangeSet C:/DbSource/DML/0003_InsertInto-public.employee.xml::7::PeterPan ran successfully in 16ms
INFO 3/3/11 10:05 AM:liquibase: ChangeSet C:/DbSource/DML/0004_InsertInto-public.employee.xml::7::PeterPan ran successfully in 33298ms
INFO 3/3/11 10:05 AM:liquibase: Successfully released change log lock
Liquibase Update Successful
C:\>liquibase --driver=org.postgresql.Driver --classpath="C:/Program Files/Java/jdk1.6.0_23/lib/postgresql-9.0-801.jdbc4.jar" --url="jdbc:postgresql:/
/localhost:5432/test_db_build" --changeLogFile=C:/DbSource/Common/00_main_changelog.xml --username=postgres --password=password rollbackCount 10
INFO 3/3/11 10:05 AM:liquibase: Successfully acquired change log lock
INFO 3/3/11 10:05 AM:liquibase: Reading from databasechangelog
INFO 3/3/11 10:05 AM:liquibase: Rolling Back Changeset:C:/DbSource/DML/0004_InsertInto-public.employee.xml::7::PeterPan::(Checksum: 3:a4b6d9d43a4175f753
f7c0a457d1ced1)
INFO 3/3/11 10:05 AM:liquibase: Rolling Back Changeset:C:/DbSource/DML/0003_InsertInto-public.employee.xml::7::PeterPan::(Checksum: 3:d7308afe0c1d4c8350
6a1ffed71a226c)
INFO 3/3/11 10:05 AM:liquibase: Rolling Back Changeset:C:/DbSource/DML/0002_Truncate-public.employee.xml::4::PeterPan::(Checksum: 3:0da476ec239364e44dda
d4f6f6da4321)
INFO 3/3/11 10:05 AM:liquibase: Rolling Back Changeset:C:/DbSource/DML/0001_InsertInto-public.employee.xml::4::PeterPan::(Checksum: 3:afdb713d4f13832efd
f0a0313ead4b84)
INFO 3/3/11 10:05 AM:liquibase: Rolling Back Changeset:C:/DbSource/Views/001_all_employees.sql::REQ111111::PeterPan::(Checksum: 3:3aee7ee7499252540b394
acb470a1ae1)
INFO 3/3/11 10:05 AM:liquibase: Successfully released change log lock
Liquibase Update Failed: No inverse to liquibase.change.core.RawSQLChange created
SEVERE 3/3/11 10:05 AM:liquibase: No inverse to liquibase.change.core.RawSQLChange created
liquibase.exception.RollbackFailedException: liquibase.exception.RollbackImpossibleException: No inverse to liquibase.change.core.RawSQLChange created
at liquibase.changelog.ChangeSet.rollback(ChangeSet.java:401)
at liquibase.changelog.visitor.RollbackVisitor.visit(RollbackVisitor.java:23)
at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:58)
at liquibase.Liquibase.rollback(Liquibase.java:250)
at liquibase.integration.commandline.Main.doMigration(Main.java:710)
at liquibase.integration.commandline.Main.main(Main.java:116)
Caused by: liquibase.exception.RollbackImpossibleException: No inverse to liquibase.change.core.RawSQLChange created
at liquibase.change.AbstractChange.generateRollbackStatementsFromInverse(AbstractChange.java:145)
at liquibase.change.AbstractChange.generateRollbackStatements(AbstractChange.java:115)
at liquibase.database.AbstractDatabase.executeRollbackStatements(AbstractDatabase.java:1029)
at liquibase.changelog.ChangeSet.rollback(ChangeSet.java:388)
... 5 more
For more information, use the --logLevel flag)
C:\>