在我的现有项目中实现Liquibase时,我遇到了一个愚蠢但又恼人的问题。经过一番挣扎,我让它工作了,当启动应用程序时,它通过主changelog和包含的changelogschangesets运行。
然后,当我在添加Luquibase Gradle插件(这也是未来支持所需要的)时,问题就出现了,因为找不到相同路径的changelog文件。
当通过application.yml文件中的设置运行应用程序时,changelog需要。
changeLog: classpath:/db/changelog-master.yml
才能运行(否则找不到文件),而我的 changelog-master 文件中的路径是:。
databaseChangeLog:
- include:
file: db/changelog/changelog.yml
但如果我使用插件命令(例如changelogSync),路径需要从src开始,比如:"我的changelog-master文件中的路径是:"。
src/main/resources/db/changelog-master.yml
这样插件才能找到变更日志。
如果能在启动应用程序和使用插件命令时使用Liquibase,我会非常感激,但我似乎找不到解决这个愚蠢问题的方法。
我在 build.gradle
是这样的。
liquibase {
activities {
main {
File propsFile = new File("${project.rootDir}/src/main/resources/liquibase.properties")
Properties properties = new Properties()
properties.load(new FileInputStream(propsFile))
changeLogFile properties['changeLogFile']
url properties['url']
username properties['username']
password properties['password']
}
}
}
而application.yml中的Liquibase设置是:
spring:
liquibase:
enabled: true
changeLog: classpath:/db/changelog-master.yml
一定有一个简单的解决方案,但我似乎找不到?欢迎询问更多的代码片段,但是根据Liquibase的文档,剩下的就很简单了,有了 液基.特性........................................................................................................................................................................................................................................... 文件等。我使用的是Liquibase core v. 3.8.9和插件版本2.0.3。謝謝。
我不能100%理解你的问题,但我认为下面的解决方案将为你的工作配置多个类路径的Liquibase。
我觉得可以做如下结构。
--src
-- main
-- resources
-- changelogs
-- migrations1.xml
-- migrations2.xml
-- ...
-- migrationsN.xml
-- migrations.xml (it's a master changeLog which includes all the other changeLogs)
试着把你的child changeLog文件的相对路径设置成这样。
<includeAll path="/changelogs" relativeToChangelogFile="true"/>
在第一个链接中 includeAll
docs中有一部分关于为什么使用它不是一个很好的做法。
虽然includeAll标签有很多有价值的用途,但它的使用可能会导致日后的问题。最需要避免的是使用includeAll标签来模拟Ruby on Rails的Active Migrations策略,即按照文件顺序运行每个文件的变化列表。虽然这看起来是个好主意,但它很快就会遇到一些问题
如果你确实选择使用includeAll标签,请确保你有一个命名策略,以确保你永远不会有冲突或需要重命名文件来改变强制重新排序。
所以也许您可以考虑使用 <include>
标签,并列出所有的子变更日志文件。
例如:
<include path="changelogs/migrations1.xml" relativeToChangelogFile="true"/>
<include path="changelogs/migrations2.xml" relativeToChangelogFile="true"/>
...etc.