Ignore SQL file for environments

最后都变了- 提交于 2019-12-11 12:56:01

问题


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>


来源:https://stackoverflow.com/questions/35205821/ignore-sql-file-for-environments

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!