忽略环境的 SQL 文件
Ignore SQL file for environments
任何人都可以建议是否有 flyway 的配置设置,以便它可以忽略某个 sql 文件,具体取决于我在哪个环境中迁移数据库?
我正在使用 maven flyway 插件并且有许多 sql 文件,例如:
V1.01_schema.sql
V1.02_data.sql
V1.03_testdata.sql
当我将数据库移至生产环境时,我不想应用 testData.sql 文件。有什么方法可以让它忽略这个文件吗?
是的,您可以定义一个特定的配置文件,告诉 flyway-maven-plugin
忽略特定的执行。这个想法是将流程分为 2 个执行:一个对环境通用,另一个特定于测试环境。使用 dev
配置文件构建时,不会跳过第二次执行,而在默认情况下会跳过。
<properties>
<flyway.prod>true</flyway.prod>
</properties>
<profiles>
<profile>
<id>dev</id>
<activation>
<property>
<name>dev</name>
<value>true</value>
</property>
</activation>
<properties>
<flyway.prod>false</flyway.prod>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>migrate-1</id>
<goals>
<goal>migrate</goal>
</goals>
<configuration>
<locations>
<location>V1.01_schema.sql</location>
<location>V1.02_data.sql</location>
</locations>
</configuration>
</execution>
<execution>
<id>migrate-test</id>
<goals>
<goal>migrate</goal>
</goals>
<configuration>
<skip>${flyway.prod}</skip>
<locations>
<location>V1.03_testdata.sql</location>
</locations>
</configuration>
</execution>
</executions>
<configuration>
<!-- common configuration here -->
</configuration>
</plugin>
</plugins>
</build>
任何人都可以建议是否有 flyway 的配置设置,以便它可以忽略某个 sql 文件,具体取决于我在哪个环境中迁移数据库?
我正在使用 maven flyway 插件并且有许多 sql 文件,例如:
V1.01_schema.sql
V1.02_data.sql
V1.03_testdata.sql
当我将数据库移至生产环境时,我不想应用 testData.sql 文件。有什么方法可以让它忽略这个文件吗?
是的,您可以定义一个特定的配置文件,告诉 flyway-maven-plugin
忽略特定的执行。这个想法是将流程分为 2 个执行:一个对环境通用,另一个特定于测试环境。使用 dev
配置文件构建时,不会跳过第二次执行,而在默认情况下会跳过。
<properties>
<flyway.prod>true</flyway.prod>
</properties>
<profiles>
<profile>
<id>dev</id>
<activation>
<property>
<name>dev</name>
<value>true</value>
</property>
</activation>
<properties>
<flyway.prod>false</flyway.prod>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-maven-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>migrate-1</id>
<goals>
<goal>migrate</goal>
</goals>
<configuration>
<locations>
<location>V1.01_schema.sql</location>
<location>V1.02_data.sql</location>
</locations>
</configuration>
</execution>
<execution>
<id>migrate-test</id>
<goals>
<goal>migrate</goal>
</goals>
<configuration>
<skip>${flyway.prod}</skip>
<locations>
<location>V1.03_testdata.sql</location>
</locations>
</configuration>
</execution>
</executions>
<configuration>
<!-- common configuration here -->
</configuration>
</plugin>
</plugins>
</build>