忽略环境的SQL文件 [英] Ignore SQL file for environments

查看:69
本文介绍了忽略环境的SQL文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告知是否有flyway的配置设置,以便它可以根据我在哪个数据库中迁移数据库而忽略某个sql文件?

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?

我正在使用Maven flyway插件,并且具有多个sql文件,例如:

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

将数据库移入生产环境时,我不想应用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?

推荐答案

是的,您可以定义一个特定的配置文件,该配置文件将告诉

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>

这篇关于忽略环境的SQL文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆