7

在 2.0 中添加了一个非常好的功能,称为 LiquiBased Formatted SQL。有关信息,请参阅此链接http://blog.liquibase.org/2010/05/liquibase-formatted-sql.html

当我尝试向我的脚本添加回滚命令时,在我的情况下,该命令正在删除创建的视图,LiquiBase 会引发错误。这是我的脚本。

--liquibase formatted sql

--changeset PeterPan:REQ111111
CREATE VIEW all_employees AS
SELECT *
FROM employee;


--rollback 
DROP VIEW all_employees;
--rollback 

我也试过这个

--liquibase formatted sql

--changeset PeterPan:REQ111111
CREATE VIEW all_employees AS
SELECT *
FROM employee;


--rollback 
DROP VIEW all_employees;

这是我的命令行输入和我得到的输出。请注意,我进行了成功的更新,然后进行了失败的回滚。还要记住,只有脚本抛出异常,视图才会被删除。如果我从构建中删除我的视图并运行相同的命令,更新和回滚都会成功完成。

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:\>
4

1 回答 1

9

好的,所以它出现在我提供的解决此问题的关键的链接上是“将 –rollback 添加到表示回滚 sql 的行的开头”。

因此,如果我将上面的脚本更新为此

--rollback DROP VIEW all_employees;

或者这种格式也可以。

--rollback DROP 
--rollback VIEW all_employees;

很高兴有开始评论和结束以允许这种类型的条目。也许喜欢

--StartRollback
DROP TABLE employee;
DROP TABLE pants;
--End Rollback

这是一个帮助澄清很多问题的网站。 http://forum.liquibase.org/#topic/49382000000028385

于 2011-03-03T19:21:12.387 回答