我正在使用liquibase和maven-3
。第一次运行按预期工作。但是,连续运行(即使 sql 文件包含更改)会失败,因为它们被视为与 liquibase 等效并被忽略(校验和)。
我的 sql 脚本中的所有 sql 操作都考虑了以前的运行,所以我不希望这种行为。使用您在下面看到的此设置,无论更改如何,我如何强制 liquibase 始终执行我的脚本?
正如您在下面看到的,我已经尝试clearCheckSums
设置为目标,并且确实清除了哈希值,但仍然没有运气(因此注释掉了)。这是我创建的个人资料
<profile>
<id>liquibase-executions</id>
<build>
<defaultGoal>process-resources</defaultGoal>
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>3.4.2</version>
<dependencies>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgres.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>update-schema</id>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
<!--<goal>clearCheckSums</goal>-->
</goals>
<configuration>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://${db.url}</url>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<changeLogFile>${basedir}/src/main/resources/liquibase.sql</changeLogFile>
</configuration>
</execution>
<execution>
<id>update-data</id>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
<!--<goal>clearCheckSums</goal>-->
</goals>
<configuration>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://${db.url}</url>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
<changeLogFile>${basedir}/src/main/resources/liquibase-populate.sql</changeLogFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
这就是我执行它的方式
mvn process-resources -Pliquibase-executions -Ddb.url=POSTGRES_IP:5432/POSTGRES_DB -Dliquibase.username=POSTGRES_USERNAME
Liquibase Maven插件需要一个更新日志文件,没有纯.sql
文件。此文件应包含您希望 Liquibase 执行的changeSets
。每次运行 Liquibase 时都可以指示运行这些 changeSets(默认情况下,它们只执行一次)。因此,无需篡改校验和。例如,您的更改日志文件可能如下所示:
<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.1.xsd">
<changeSet id="your-id" author="msp" runAlways="true">
...
</changeSet>
</databaseChangeLog>
实现预期行为的重要部分是在 liquibase 变更集中设置 runAlways="true"
属性。