简体   繁体   中英

Liquibase migration with H2 and Spring boot

I use Spring boot and H2 DB. I want to include Liquibase in my app. I have have multiple modules app. There are entity, dao, service, controller, etc modules. I created Liquibase files in Dao module. This is 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

This is 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

And here is 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>

And I have an error:

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

But, I think that I don't need to specify files form master.xml in properties. Please, help. enter image description here

Looks like the path to the changelog-project-v-1.0.0-cumulative.xml is incorrect. Try using relativeToChangelogFile="true"

In master.xml put the following:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM