maven liquibase中的SQL文件从未执行

5vf7fwbs  于 2023-03-29  发布在  Maven
关注(0)|答案(2)|浏览(291)

我使用liquibase与maven和我有一个配置为单元测试

<configuration>
    <changeLogFile>src/main/resources/db/changelog/changelog-master.xml</changeLogFile>
    <driver>org.hsqldb.jdbcDriver</driver>
    <url>jdbc:hsqldb:mem:testdb;shutdown=true</url>                 
    <referenceUrl>persistence:webapp</referenceUrl>                 
    <username>sa</username>
    <password></password>
</configuration>

在我的更新日志中,我使用sqlFile标记来执行插入语句。

<changeSet id="18" author="naslami">
    <sqlFile path="src/main/resources/db/changelog/inserts.sql" />
</changeSet>

但是当我查看日志时,* insert.sql * 文件从未执行过。你知道为什么liquibase不执行 * insert.sql * 文件吗?

<plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>${liquibase.version}</version>
            <executions>
                <execution>
                    <id>install</id>
                    <phase>install</phase>                                                                  
                    <goals>
                        <goal>update</goal>
                    </goals>
                    <configuration>
                        <changeLogFile>src/main/resources/db/changelog/changelog-master.xml</changeLogFile>
                        <driver>com.mysql.jdbc.Driver</driver>
                        <url>jdbc:mysql://localhost:3306/mydb</url>                 
                        <referenceUrl>persistence:webapp</referenceUrl>                 
                        <username>user</username>
                        <password>password</password>
                    </configuration> 
                </execution>
                <execution>
                    <id>test</id>
                    <phase>test</phase>                                                                  
                    <goals>
                        <goal>update</goal>
                    </goals>
                    <configuration>
                        <changeLogFile>src/main/resources/db/changelog/changelog-master.xml</changeLogFile>
                        <driver>org.hsqldb.jdbcDriver</driver>
                        <url>jdbc:hsqldb:mem:testdb;shutdown=true</url>                 
                        <referenceUrl>persistence:webapp</referenceUrl>                 
                        <username>sa</username>
                        <password></password>
                    </configuration> 
                </execution>
            </executions>
        </plugin>
zaqlnxep

zaqlnxep1#

您的<sqlFile>标记需要一个名为“dbms”的附加属性。dbms指定您的数据库提供程序。当您使用“org.hsqldb.jdbcDriver”时,您需要以下内容:

<changeSet id="18" author="naslami">
    <sqlFile dbms="hsqldb" path="src/main/resources/db/changelog/inserts.sql" />
</changeSet>

或:

<changeSet id="18" author="naslami">
    <sqlFile dbms="h2" path="src/main/resources/db/changelog/inserts.sql" />
</changeSet>

liquibase文档在此http://www.liquibase.org/documentation/changes/sql_file.html

hrirmatl

hrirmatl2#

只需从path标记中删除src/main/resources/

<changeSet id="18" author="naslami">
    <sqlFile path="db/changelog/inserts.sql" />
</changeSet>

相关问题