使用 H2 和 Spring 启动的 Liquibase 迁移
Liquibase migration with H2 and Spring boot
我使用 Spring 引导和 H2 数据库。我想在我的应用程序中包含 Liquibase。我有多个模块应用程序。有entity、dao、service、controller等模块。我在 Dao 模块中创建了 Liquibase 文件。
这是 application.property:
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=password
spring.liquibase.change-log=classpath:db/migration/master.xml
这是liquibase.property:
classpath=
changeLogFile=db/migration/master.xml
url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE
username=sa
password=password
driver=org.h2.Driver
这里是 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"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<include file="v-1-0-0/changelog-project-v-1.0.0-cumulative.xml"/>
<include file="v-1-0-1/changelog-project-v-1.0.1-cumulative.xml"/>
</databaseChangeLog>
我有一个错误:
Invocation of init method failed; nested exception is liquibase.exception.ChangeLogParseException: liquibase.exception.SetupException: The file v-1-0-0/changelog-project-v-1.0.0-cumulative.xml was not found in
- Spring resources
但是,我认为我不需要在属性中指定 master.xml 形式的文件。
请帮忙。
enter image description here
看起来 changelog-project-v-1.0.0-cumulative.xml
的路径不正确。尝试使用 relativeToChangelogFile="true"
在 master.xml
中输入以下内容:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<include file="v-1-0-0/changelog-project-v-1.0.0-cumulative.xml" relativeToChangelogFile="true"/>
<include file="v-1-0-1/changelog-project-v-1.0.1-cumulative.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>
我使用 Spring 引导和 H2 数据库。我想在我的应用程序中包含 Liquibase。我有多个模块应用程序。有entity、dao、service、controller等模块。我在 Dao 模块中创建了 Liquibase 文件。 这是 application.property:
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=password
spring.liquibase.change-log=classpath:db/migration/master.xml
这是liquibase.property:
classpath=
changeLogFile=db/migration/master.xml
url=jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE
username=sa
password=password
driver=org.h2.Driver
这里是 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"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<include file="v-1-0-0/changelog-project-v-1.0.0-cumulative.xml"/>
<include file="v-1-0-1/changelog-project-v-1.0.1-cumulative.xml"/>
</databaseChangeLog>
我有一个错误:
Invocation of init method failed; nested exception is liquibase.exception.ChangeLogParseException: liquibase.exception.SetupException: The file v-1-0-0/changelog-project-v-1.0.0-cumulative.xml was not found in
- Spring resources
但是,我认为我不需要在属性中指定 master.xml 形式的文件。 请帮忙。 enter image description here
看起来 changelog-project-v-1.0.0-cumulative.xml
的路径不正确。尝试使用 relativeToChangelogFile="true"
在 master.xml
中输入以下内容:
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">
<include file="v-1-0-0/changelog-project-v-1.0.0-cumulative.xml" relativeToChangelogFile="true"/>
<include file="v-1-0-1/changelog-project-v-1.0.1-cumulative.xml" relativeToChangelogFile="true"/>
</databaseChangeLog>