我在maven中使用liquibase,我有一个单元测试的配置
<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>
<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>
这里的利口酒医生http://www.liquibase.org/documentation/changes/sql_file.html
只需从path
标签中删除src/main/resources/
<changeSet id="18" author="naslami">
<sqlFile path="db/changelog/inserts.sql" />
</changeSet>