[英]Using liquibase file paths via both maven and spring
I update scheme and initial data in spring context using the following beean: 我使用以下beean在spring上下文中更新方案和初始数据:
<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
<property name="dataSource" ref="dataSource" />
<property name="changeLog" value="classpath:db/changelog/db.changelog-master.xml" />
<property name="dropFirst" value="true" />
</bean>
I also use Maven liquibase plugin to generate sql scripts in order to see what tables are created and etc. 我还使用Maven liquibase插件生成sql脚本,以便查看创建了哪些表等。
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>2.0.5</version>
<configuration>
<!--mvn initialize liquibase:updateSQL-->
<propertyFile>src/main/resources/db/config/liquibase-gensql-data-access.properties</propertyFile>
<changeLogFile>src/main/resources/db/changelog/db.changelog-master.xml</changeLogFile>
</configuration>
</plugin>
The db.changelog-master.xml
file includes child liquibase changelog files. db.changelog-master.xml
文件包含子liquibase changelog文件。 The problem, how to refer to them from the master. 问题是,如何从主人那里引用它们。 When I use Spring I have to use the following path via classpath: 当我使用Spring时,我必须通过classpath使用以下路径:
<include file="classpath:/db/changelog/db.changelog-1.0.xml"/>
When Maven is used, the path is: 使用Maven时,路径是:
<include file="src/main/resources/db/changelog/db.changelog-1.0.xml"/>
I'd like to have the same configuration for both cases. 我想对两种情况都有相同的配置。 How can I archive it? 我该如何存档?
I commented on Igor's answer, his solution does not seem to work. 我评论了伊戈尔的答案,他的解决方案似乎没有用。
In order to solve this, I just pushed a patch to Liquibase: https://github.com/liquibase/liquibase/pull/187 . 为了解决这个问题,我只是将补丁推送到Liquibase: https : //github.com/liquibase/liquibase/pull/187 。 This should be merged in 3.0.6-SNAPSHOT and therefore shortly available in 3.0.6. 这应该在3.0.6-SNAPSHOT中合并,因此很快就会在3.0.6中提供。
With this change, you can now configure SpringLiquibase
with this additional line: 通过此更改,您现在可以使用以下附加行配置SpringLiquibase
:
<property name="ignoringClasspathPrefix" value="true" />
Another example/usecase requiring this change can be found here: https://github.com/LateralThoughts/spring-liquibase-extensions . 可以在此处找到需要此更改的另一个示例/用例: https : //github.com/LateralThoughts/spring-liquibase-extensions 。
I think if you change your Maven path from 我想如果你改变你的Maven路径
<changeLogFile>src/main/resources/db/changelog/db.changelog-master.xml</changeLogFile>
to 至
<changeLogFile>db/changelog/db.changelog-master.xml</changeLogFile>
and update db.changelog-master.xml file for all included files to use path relative to src/main/resources directory, it will fix the problem. 并更新所有包含文件的db.changelog-master.xml文件以使用相对于src / main / resources目录的路径,它将解决问题。
I solved this problem by using the same path to changeLog files in Spring, maven and integration test which call Liquibase. 我通过在Spring,maven和集成测试中使用相同的路径来更改日志文件来解决这个问题,该测试调用了Liquibase。 All my changelog files are located under /src/main/resources/db directory in one of the Maven modules within a project. 我的所有更改日志文件都位于项目中某个Maven模块的/ src / main / resources / db目录下。
Maven profile which runs Liquibase, notice path: db/masterChangeLog.xml 运行Liquibase的Maven配置文件,通知路径:db / masterChangeLog.xml
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>*** Install a last major release version of db ***</id>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
</goals>
<configuration>
<changeLogFile>db/masterChangeLog.xml</changeLogFile>
<contexts>dbBuildContext, dmlDevContext</contexts>
<propertyFile>db/liquibase-${user.name}.properties</propertyFile>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<logging>debug</logging>
</configuration>
</execution>
db/masterChangeLog.xml file includes these files: db / masterChangeLog.xml文件包含以下文件:
<include file="db/install.xml"/>
<include file="db/update.xml"/>
db/install.xml file includes other changelog files (so does update.xml): db / install.xml文件包含其他changelog文件(update.xml也是如此):
<includeAll path="db/install/seq"/>
<includeAll path="db/install/tab"/>
<includeAll path="db/install/cst"/>
<includeAll path="db/latest/vw" />
Spring context executes the same set of db scripts upon app startup as follows: Spring上下文在应用启动时执行相同的db脚本集,如下所示:
<bean id="liquibase" class="liquibase.integration.spring.SpringLiquibase">
<property name="dataSource" ref="baseCostManagementDataSource" />
<property name="changeLog" value="classpath:db/masterChangelog.xml" />
<property name="contexts" value="dbBuildContext, dmlDevContext" />
</bean>
Specify the logicalFilePath attribute in each databaseChangeLog file. 在每个databaseChangeLog文件中指定logicalFilePath属性。 See http://www.liquibase.org/documentation/databasechangelog.html 请参阅http://www.liquibase.org/documentation/databasechangelog.html
The Maven Plugin has the configuration property changeLogDirectory in recent versions. Maven插件在最近的版本中具有配置属性changeLogDirectory。
Hence setting <changeLogDirectory>src/main/resources</changeLogDirectory>
should achieve what you want. 因此设置<changeLogDirectory>src/main/resources</changeLogDirectory>
应该达到你想要的效果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.