从命令行进行Liquibase回滚不起作用 [英] Liquibase rollback from command line not working

查看:62
本文介绍了从命令行进行Liquibase回滚不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows环境中执行tomcat应用程序,该环境在部署时会在Oracle db上创建/更新DB Schema.为此,我使用的是Liquibase SDK 3.3.2.因此,基本上,我将SDK称为告诉它从我的changelog.xml中进行更新.这部分工作正常.代码来自Java类

I am doing an tomcat appliaction in a windows enviroment that when deployed creates/updates the DB Schema on the oracle db. For this I am using the Liquibase SDK 3.3.2. So basically I call the SDK an tell it to do an update from my changelog.xml. This parts works as fine. The code form the java class

...
Liquibase liquibase = new Liquibase(CHANGE_LOG,
                new ClassLoaderResourceAccessor(getClass().getClassLoader()), db);

liquibase.update("");

问题是,当出现问题并且我从命令行执行回滚时,什么也没有发生.我没有异常或错误消息.只是一条消息"Rollback成功",但是在DB中根本没有任何更改.现在有趣的是,当我从 cmd 更新我的更改日志文件,然后也从 cmd 进行回滚时,回滚工作.命令行调用如下所示:

The problem is, when something goes wrong and I do a Rollback from the command line nothing happens. I get no exceptions or error messages. Just a message "Rollback succesfull", but in the DB there is no change at all. Now the funny thing is when I do the update for my change log file from cmd and then do the rollback also from the cmd then the Rollback works. The command line call looks as following:

Liquibase --changeLogFile=C:\myProject\src\main\resources\database\master.xml  --logLevel=DEBUG rollbackCount 5

我的liquibase.properties文件如下所示:

My liquibase.properties file looks as following:

driver: oracle.jdbc.OracleDriver 
classpath:ojdbc6.jar 
url: jdbc:oracle:thin:@192.168.56.101:1521:orcl
username: myUser
password: mypassword

这个问题有些人知道为什么会这样吗?SDK 和 cmd 工具之间是否有任何不兼容?

The question does some know why does this happens? Are there any incompatibilties between SDK and cmd tool?

推荐答案

问题是更改日志文件的路径.Liquibase将chengeLog的路径存储在某处,并在调用时将其映射到给定的更改日志.如果它们不同,则Liquibase将继续运行而不会发出changeLog和警告.

The problem was the path to the change log file. Liquibase stores somewhere the path to the chengeLog and comapres it to the given change log at calling. If they are not the same Liquibase will just go on without a changeLog and warning.

因此,在我的情况下,当从tomcat应用程序调用Liquibase时,路径为: database \ master.xml ,而从控制台调用时,路径为 C:\ myProject \ srccomand行中的\ main \ resources \ database \ master.xml .尽管Liquibase知道changeLog的路径,但这导致该方法返回null.所以这就是它不起作用的原因.

So in my case when calling Liquibase from the tomcat app the path was: database\master.xml and when calling it from the console I gave the path C:\myProject\src\main\resources\database\master.xml in the comand line. This caused the method to return null although Liquibase knew the path to the changeLog. So that was the reason it did not worked.

一种解决方法是使用相对路径从命令行在与应用程序相同的文件夹中调用liquibase.

A workaround is to call liquibase from the command line from the same folder as the application did using a relative path.

技术原因:在调试LB之后,我发现了这一点.方法 DatabaseChageLog.getChangeSet()返回null,但chanegeLog路径正确.当在方法 Liquibase.rollback(int changesToRollback,Contexts contexts,LabelExpression labelExpression)中为 RollbackVisitor 运行时创建 ChangeLogIterator 时,会发生这种情况.使用 ValidationVisitor 不会发生这种情况,因为 ChangeLogIterator 是用不同的方式创建的,这就是为什么我没有收到任何错误\警告

Technical reason: After debuggin LB I found this. The Method DatabaseChageLog.getChangeSet() is returning null althoug the chanegeLog path is correct. This happens when creating the ChangeLogIterator for runnign the RollbackVisitor in the method Liquibase.rollback(int changesToRollback, Contexts contexts, LabelExpression labelExpression). This do not happens with the ValidationVisitor becasuse the ChangeLogIterator is created differently, that is why I did not get any error\warnings

这篇关于从命令行进行Liquibase回滚不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆