Ignore SQL file for environments

2019-08-13 17:03发布

问题:

Can anyone advise if there is a configuration setting for flyway so that it can ignore a certain sql file depending on which environment I am migrating the database in?

I am using the maven flyway plugin and have a number of sql files for eg:

V1.01_schema.sql
V1.02_data.sql
V1.03_testdata.sql

When I move my database into production I do not want to apply the testData.sql file. Any way that I can get it to ignore this file?

回答1:

Yes, you can define a specific profile that will tell flyway-maven-plugin to ignore a specific execution. The idea is to split the process into 2 executions: one that will be common to environments and another one specific to the test environment. When building with the dev profile, the second execution will not be skipped whereas it will be skipped in the default case.

<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>


标签: maven flyway