在我现有项目中实现Liquibase时,我遇到了一个愚蠢但烦人的问题。经过很多努力后,我在启动应用程序时使其正常工作,它贯穿主变更日志和随附的变更日志/变更集。
然后,当我添加Luquibase Gradle插件(以后的支持也需要)时发生了问题,因为找不到具有相同路径的changelog文件。
通过application.yml文件中的设置运行应用程序时,更改日志必须为:
changeLog: classpath:/db/changelog-master.yml
工作(否则找不到该文件),并且我的changelog-master文件中的路径为:
databaseChangeLog: - include: file: db/changelog/changelog.yml
但是,如果我使用插件命令(例如,changelogSync),则该路径需要来自src,例如:
src/main/resources/db/changelog-master.yml
让插件找到更改日志。
在启动应用程序以及在插件中使用命令时都能够使用Liquibase确实会有所帮助,但是我似乎找不到解决这种愚蠢问题的方法。
我在
build.gradle
中的 Activity 是这样的: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.propterties文件等),其余内容非常简单。
我正在使用Liquibase core v.8.9.3和插件版本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
文档的第一个链接中,有一部分说明了为什么使用它不是一个很好的做法因此,也许您可以考虑使用
<include>
标记并列出所有子级changeLog文件。例如。:
<include path="changelogs/migrations1.xml" relativeToChangelogFile="true"/>
<include path="changelogs/migrations2.xml" relativeToChangelogFile="true"/>
...etc.