简体   繁体   中英

liquibase does not run with java -jar SpringBoot

I am trying to integrate liquibase with an existing project. When testing liquibase locally I have been using IntelliJ which I think is equivalent to mvn spring-boot:run in this case when the app starts liquibase runs the update and checks that all the changelogs have been completed.

When I compile into a jar ( mvn clean install ) and run java -jar app.jar liquibase simply prints out:

 15:17:08.769 [main] INFO  liquibase.lockservice - Successfully acquired change log lock
 15:17:09.013 [main] INFO  liquibase.changelog - Creating database history table with name: "app".databasechangelog
 15:17:09.028 [main] INFO  liquibase.changelog - Reading from "app".databasechangelog
 15:17:09.078 [main] INFO  liquibase.lockservice - Successfully released change log lock

and does not apply any of the changesets so obviously it immediately crashes because none of the tables have been set up (if I'm running it on a new database). My understanding is that in a spring boot app with default configuration liquibase should run on start up. I thought that this could be a dependency issue but then why would liquibase be running at all?

Can anyone give some pointers on what I can check to support this? Does liquibase just not run on startup unless it's a specific "spring boot run"?

Thanks

Changelogs added by request:

db.changelog-root.xml

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<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 http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.5.xsd"
                   logicalFilePath="root"
>
    <!-- NOTE: path is relative from src/main/resources -->
    <includeAll path="./db/changelog"/>
</databaseChangeLog>

changelog-2.5.0.xml

<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<databaseChangeLog logicalFilePath="2.5.0" xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:pro="http://www.liquibase.org/xml/ns/pro" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-4.1.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd">
    <preConditions onFail="WARN" onFailMessage="Non postgres databases are not supported for SI, good luck!">
        <dbms type="postgresql"/>
    </preConditions>
    <changeSet author="kidd (manual)" id="tag-version-2.1.0">
        <tagDatabase tag="2.5.0"/>
    </changeSet>

    <!-- mobile_uid_seq -->
    <changeSet author="kidd (modified)" id="1635825727316-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <sequenceExists sequenceName="mobile_uid_seq"/>
            </not>
        </preConditions>
        <createSequence cacheSize="1" cycle="false" dataType="bigint" incrementBy="1" maxValue="9223372036854775807" minValue="-1" sequenceName="mobile_uid_seq" startValue="-1"/>
    </changeSet>

<!-- ... a lot more changesets --> 
</databaseChangeLog>

The problem was solved by changing

<includeAll path="./db/changelog"/> to <includeAll path="/db/changelog"/> . Though if anyone could explain why this would be different between running the compiled jar ( java -jar app.jar ) and mvn:spring-boot run that would be interesting to me. I understand that the filepaths change when compiled however, even looking in the target folder it should still be the same relevant path right (in this case db is the root folder following the normal liquibase layout). So still slightly confused as to why ./ should not work in this case.

Regardless, if anyone faces this problem again do not use relative paths even when within the resources folder!

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