liquibase maven插件多个changeLogFile
liquibase maven plugin multiple changeLogFile
我正在使用 liquibase maven plugin
通过 jenkins
自动构建来更新数据库更改。
我的 pom.xml
里有这个
<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>9.5</version>
</dependency>
</dependencies>
<configuration>
<changeLogFile>${basedir}/src/main/resources/schema.sql</changeLogFile>
<changeLogFile>${basedir}/src/main/resources/data.sql</changeLogFile>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://${db.url}</url>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
</configuration>
</plugin>
我需要在 data.sql
之前 运行 schema.sql
。当我 运行 这在本地工作时。当我 运行 它通过 jenkins 时 schema changeLogFile
执行第二个,所以为了让它工作我颠倒了逗号。
问题:执行顺序是什么?我做错了什么吗?
official goal documentation 指定只预见一个条目:
changeLogFile:
Specifies the change log file to use for Liquibase.
- Type:
java.lang.String
- Required: No
- Expression:
${liquibase.changeLogFile}
您可以添加更多条目,但它们将被忽略并且 maven 不会抱怨:它不验证插件配置的内容,它不能,因为那部分取决于插件并且 maven 事先不知道。即通用。
为了确保确定的顺序并执行两个 changeLogFile
,您应该指定多个插件 executions
,如下所示:
<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>9.5</version>
</dependency>
</dependencies>
<configuration>
<changeLogFile>${basedir}/src/main/resources/schema.sql</changeLogFile>
<changeLogFile>${basedir}/src/main/resources/data.sql</changeLogFile>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://${db.url}</url>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
</configuration>
<executions>
<execution>
<id>update-schema</id>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
</goals>
<configuration>
<changeLogFile>${basedir}/src/main/resources/schema.sql</changeLogFile>
</configuration>
</execution>
<execution>
<id>update-data</id>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
</goals>
<configuration>
<changeLogFile>${basedir}/src/main/resources/data.sql</changeLogFile>
</configuration>
</execution>
</executions>
</plugin>
注意:我们为 executions
部分之外的所有执行指定一个通用配置,然后每个 execution
我们只定义附加配置,每次都是不同的文件。
确定性顺序由Maven保证:对于同一个插件,对于同一个阶段,将遵守POM中声明的顺序。
但是,此执行现在将作为 process-resources
阶段的一部分成为您构建的一部分,这可能不是您想要的。所以在这种情况下,最好将其移动到如下配置文件:
<profiles>
<profile>
<id>liquibase-executions</id>
<build>
<defaultGoal>process-resources</defaultGoal>
<plugins>
<!-- MOVE HERE liquibase plugin configuration and executions -->
</plugins>
</build>
</profile>
</profiles>
然后执行以下(也根据您的评论):
mvn -Pliquibase-executions -Ddb.url=IP:PORT/DB -Dliquibase.username=USERNAME
我正在使用 liquibase maven plugin
通过 jenkins
自动构建来更新数据库更改。
我的 pom.xml
<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>9.5</version>
</dependency>
</dependencies>
<configuration>
<changeLogFile>${basedir}/src/main/resources/schema.sql</changeLogFile>
<changeLogFile>${basedir}/src/main/resources/data.sql</changeLogFile>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://${db.url}</url>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
</configuration>
</plugin>
我需要在 data.sql
之前 运行 schema.sql
。当我 运行 这在本地工作时。当我 运行 它通过 jenkins 时 schema changeLogFile
执行第二个,所以为了让它工作我颠倒了逗号。
问题:执行顺序是什么?我做错了什么吗?
official goal documentation 指定只预见一个条目:
changeLogFile:
Specifies the change log file to use for Liquibase.
- Type:
java.lang.String
- Required: No
- Expression:
${liquibase.changeLogFile}
您可以添加更多条目,但它们将被忽略并且 maven 不会抱怨:它不验证插件配置的内容,它不能,因为那部分取决于插件并且 maven 事先不知道。即通用。
为了确保确定的顺序并执行两个 changeLogFile
,您应该指定多个插件 executions
,如下所示:
<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>9.5</version>
</dependency>
</dependencies>
<configuration>
<changeLogFile>${basedir}/src/main/resources/schema.sql</changeLogFile>
<changeLogFile>${basedir}/src/main/resources/data.sql</changeLogFile>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://${db.url}</url>
<promptOnNonLocalDatabase>false</promptOnNonLocalDatabase>
</configuration>
<executions>
<execution>
<id>update-schema</id>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
</goals>
<configuration>
<changeLogFile>${basedir}/src/main/resources/schema.sql</changeLogFile>
</configuration>
</execution>
<execution>
<id>update-data</id>
<phase>process-resources</phase>
<goals>
<goal>update</goal>
</goals>
<configuration>
<changeLogFile>${basedir}/src/main/resources/data.sql</changeLogFile>
</configuration>
</execution>
</executions>
</plugin>
注意:我们为 executions
部分之外的所有执行指定一个通用配置,然后每个 execution
我们只定义附加配置,每次都是不同的文件。
确定性顺序由Maven保证:对于同一个插件,对于同一个阶段,将遵守POM中声明的顺序。
但是,此执行现在将作为 process-resources
阶段的一部分成为您构建的一部分,这可能不是您想要的。所以在这种情况下,最好将其移动到如下配置文件:
<profiles>
<profile>
<id>liquibase-executions</id>
<build>
<defaultGoal>process-resources</defaultGoal>
<plugins>
<!-- MOVE HERE liquibase plugin configuration and executions -->
</plugins>
</build>
</profile>
</profiles>
然后执行以下(也根据您的评论):
mvn -Pliquibase-executions -Ddb.url=IP:PORT/DB -Dliquibase.username=USERNAME