为什么 liquibase 无法解析 db.changelog 类路径?
Why liquibase unable to resolved the db.changelog classpath?
这里是结构,maven 依赖 jar 项目之一,其中一个包含 liquibase 更改日志 classpath 如下:
chorke─init─change-1.0.00.GA.jar!
└─ META-INF/
└─ migrations/
├─ db.changelog-master.xml
├─ config/
│ ├─ db.changelog-config.xml
│ ├─ db.changelog-property.xml
│ └─ db.changelog-restrict.xml
└─ change/
├─ db.changelog-1.xml
├─ db.changelog-2.xml
├─ V1/
│ ├─ db.changelog-1.0.xml
│ ├─ db.changelog-1.1.xml
│ ├─ V1.0/
│ │ ├─ db.changelog-1.0.00.xml
│ │ ├─ db.changelog-1.0.01.xml
│ │ ├─ V1.0.00/
│ │ │ ├─ db.changelog-1.0.00.000.xml
│ │ │ ├─ db.changelog-1.0.00.001.xml
│ │ │ ├─ db.changelog-1.0.00.002.xml
│ │ │ └─ db.changelog-1.0.00.999.xml
│ │ └─ V1.0.01/
│ │ ├─ db.changelog-1.0.01.000.xml
│ │ ├─ db.changelog-1.0.01.001.xml
│ │ ├─ db.changelog-1.0.01.002.xml
│ │ └─ db.changelog-1.0.01.999.xml
│ └─ V1.1/
│ ├─ db.changelog-1.1.00.xml
│ ├─ db.changelog-1.1.01.xml
│ ├─ V1.1.00/db.changelog-1.1.00.###.xml
│ └─ V1.1.01/db.changelog-1.1.01.###.xml
└─ V2/
├─ db.changelog-2.#.xml
└─ V2.#/V2.#.##/db.changelog-2.#.##.###.xml
这里是db.changelog-master.xml
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<includeAll path="config" relativeToChangelogFile="true"/>
<include file="change/db.changelog-1.xml" relativeToChangelogFile="true"/>
<include file="change/db.changelog-2.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
哪个由spring-boot加载application.properties
如下
liquibase.change-log=classpath:/META-INF/migrations/db.changelog-master.xml
在同一个项目中执行得很好。在依赖项目上执行如下:
- DATABASECHANGELOG table 创建
- DATABASECHANGELOGLOCK table 已创建
- 但是没有执行更新迁移!
当db.changelog-master.xml被liquibase maven插件加载时如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- intentionally configuration skipped -->
<dependencies>
<dependency>
<groupId>org.chorke.init</groupId>
<artifactId>chorke-init-change</artifactId>
<version>1.0.00.GA</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.5.3</version>
<configuration>
<propertyFileWillOverride>true</propertyFileWillOverride>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<changeLogFile>classpath:/META-INF/migrations/db.changelog-master.xml</changeLogFile>
<propertyFile>${project.build.directory}/test-classes/liquibase-update.properties</propertyFile>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.14</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
消息错误:
Failed to execute goal
org.liquibase:liquibase-maven-plugin:3.5.3:update (default) on project
chorke-init-migrat: Error setting up or running Liquibase:
classpath:/META-INF/migrations/db.changelog-master.xml does not exist
在这种情况下,您的指导方针预计对于使用 spring-boot 的依赖项目没有错误 liquibase 迁移或 liquibase-maven-plugin
为 chorke─init─change-1.0.00.GA.jar
提到的结构包含 liquibase 更改日志 在 classpath 中足够好并且 spring-boot application.properties
也完全配置好了。但是在liquibase-maven-plugin配置中出现了一些愚蠢的错误,应该更正如下:
<configuration>
<propertyFileWillOverride>true</propertyFileWillOverride>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<changeLogFile>META-INF/migrations/db.changelog-master.xml</changeLogFile>
<propertyFile>liquibase-update.properties</propertyFile>
</configuration>
liquibase-maven-plugin 配置中有两个错误,它们是:
- 第一个
changeLogFile
- 第二个
propertyFile
无需为changeLogFile
使用classpath:
或classpath:/
等前缀,也无需为propertyFile
使用${project.build.directory}/test-classes/
等绝对或相对路径.保持简单。 liquibase-maven-plugin如何从classpath
.
解析是自己的事
除此之外,还有一些额外的提示可能有助于轻松进行便携式迁移,如下所示
- 始终为每个
databaseChangeLog
使用相对路径。您的 db.changelog-master.xml 中提到了示例
- 为每个
changeSet
使用逻辑文件路径
这里是逻辑文件路径的例子:
<changeSet author="chorkeorg" id="1508234245316-1" logicalFilePath="V0/V0.0/V0.0.00/db.changelog-0.0.00.000.xml">
<createSequence cacheSize="20" cycle="false"
incrementBy="1" maxValue="999999999999999999999999999" minValue="10001"
ordered="false" sequenceName="CK_SQ_AUTHOR" startValue="10181" />
</changeSet>
希望能妥善解决您的问题。
这里是结构,maven 依赖 jar 项目之一,其中一个包含 liquibase 更改日志 classpath 如下:
chorke─init─change-1.0.00.GA.jar!
└─ META-INF/
└─ migrations/
├─ db.changelog-master.xml
├─ config/
│ ├─ db.changelog-config.xml
│ ├─ db.changelog-property.xml
│ └─ db.changelog-restrict.xml
└─ change/
├─ db.changelog-1.xml
├─ db.changelog-2.xml
├─ V1/
│ ├─ db.changelog-1.0.xml
│ ├─ db.changelog-1.1.xml
│ ├─ V1.0/
│ │ ├─ db.changelog-1.0.00.xml
│ │ ├─ db.changelog-1.0.01.xml
│ │ ├─ V1.0.00/
│ │ │ ├─ db.changelog-1.0.00.000.xml
│ │ │ ├─ db.changelog-1.0.00.001.xml
│ │ │ ├─ db.changelog-1.0.00.002.xml
│ │ │ └─ db.changelog-1.0.00.999.xml
│ │ └─ V1.0.01/
│ │ ├─ db.changelog-1.0.01.000.xml
│ │ ├─ db.changelog-1.0.01.001.xml
│ │ ├─ db.changelog-1.0.01.002.xml
│ │ └─ db.changelog-1.0.01.999.xml
│ └─ V1.1/
│ ├─ db.changelog-1.1.00.xml
│ ├─ db.changelog-1.1.01.xml
│ ├─ V1.1.00/db.changelog-1.1.00.###.xml
│ └─ V1.1.01/db.changelog-1.1.01.###.xml
└─ V2/
├─ db.changelog-2.#.xml
└─ V2.#/V2.#.##/db.changelog-2.#.##.###.xml
这里是db.changelog-master.xml
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<includeAll path="config" relativeToChangelogFile="true"/>
<include file="change/db.changelog-1.xml" relativeToChangelogFile="true"/>
<include file="change/db.changelog-2.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
哪个由spring-boot加载application.properties
如下
liquibase.change-log=classpath:/META-INF/migrations/db.changelog-master.xml
在同一个项目中执行得很好。在依赖项目上执行如下:
- DATABASECHANGELOG table 创建
- DATABASECHANGELOGLOCK table 已创建
- 但是没有执行更新迁移!
当db.changelog-master.xml被liquibase maven插件加载时如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- intentionally configuration skipped -->
<dependencies>
<dependency>
<groupId>org.chorke.init</groupId>
<artifactId>chorke-init-change</artifactId>
<version>1.0.00.GA</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.5.3</version>
<configuration>
<propertyFileWillOverride>true</propertyFileWillOverride>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<changeLogFile>classpath:/META-INF/migrations/db.changelog-master.xml</changeLogFile>
<propertyFile>${project.build.directory}/test-classes/liquibase-update.properties</propertyFile>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>update</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.14</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
消息错误:
Failed to execute goal
org.liquibase:liquibase-maven-plugin:3.5.3:update (default) on project
chorke-init-migrat: Error setting up or running Liquibase:
classpath:/META-INF/migrations/db.changelog-master.xml does not exist
在这种情况下,您的指导方针预计对于使用 spring-boot 的依赖项目没有错误 liquibase 迁移或 liquibase-maven-plugin
为 chorke─init─change-1.0.00.GA.jar
提到的结构包含 liquibase 更改日志 在 classpath 中足够好并且 spring-boot application.properties
也完全配置好了。但是在liquibase-maven-plugin配置中出现了一些愚蠢的错误,应该更正如下:
<configuration>
<propertyFileWillOverride>true</propertyFileWillOverride>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<changeLogFile>META-INF/migrations/db.changelog-master.xml</changeLogFile>
<propertyFile>liquibase-update.properties</propertyFile>
</configuration>
liquibase-maven-plugin 配置中有两个错误,它们是:
- 第一个
changeLogFile
- 第二个
propertyFile
无需为changeLogFile
使用classpath:
或classpath:/
等前缀,也无需为propertyFile
使用${project.build.directory}/test-classes/
等绝对或相对路径.保持简单。 liquibase-maven-plugin如何从classpath
.
除此之外,还有一些额外的提示可能有助于轻松进行便携式迁移,如下所示
- 始终为每个
databaseChangeLog
使用相对路径。您的 db.changelog-master.xml 中提到了示例
- 为每个
changeSet
使用逻辑文件路径
这里是逻辑文件路径的例子:
<changeSet author="chorkeorg" id="1508234245316-1" logicalFilePath="V0/V0.0/V0.0.00/db.changelog-0.0.00.000.xml">
<createSequence cacheSize="20" cycle="false"
incrementBy="1" maxValue="999999999999999999999999999" minValue="10001"
ordered="false" sequenceName="CK_SQ_AUTHOR" startValue="10181" />
</changeSet>
希望能妥善解决您的问题。