【问题标题】:Flyway location - Point to single sql scriptFlyway 位置 - 指向单个 sql 脚本
【发布时间】:2016-03-25 16:57:04
【问题描述】:

我在这样的文件夹中有脚本:

D:/dev/DatabaseSetup/oracle/010__script.sql
D:/dev/DatabaseSetup/oracle/020__script.sql
D:/dev/DatabaseSetup/oracle/030__script.sql
D:/dev/DatabaseSetup/oracle/040__script.sql
D:/dev/DatabaseSetup/oracle/050__script.sql

我想将所有脚本保存在同一个文件夹中,但在迁移时忽略其中一些。准确地说,我只想包含这些脚本

<locations>
    <location>filesystem:oracle/020__script.sql</location>
    <location>filesystem:oracle/030__script.sql</location>
    <location>filesystem:oracle/040__script.sql</location>
</locations>

pom.xml 的路径是D:/dev/DatabaseSetup/oracle/pom.xml

我读了这个question ,但发现我不能为迁移指定单个 sql 脚本(在接受的答案中,它使用指向 java 包的类路径)。

有可能吗?我收到以下错误:

[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:3.2.1:migrate (default-cli) on proje
ct DatabaseSetup: org.flywaydb.core.api.FlywayException: Unable to scan for SQL migrations in lo
cation: filesystem:D:/dev/DatabaseSetup/oracle/020__script.sql: Invalid filesystem path:
D:/dev/DatabaseSetup/oracle/020__script.sql -> [Help 1]

当我将&lt;locations&gt; 更改为

<locations>
    <location>filesystem:oracle</location>
</locations>

flyway 执行所有脚本。

【问题讨论】:

    标签: java maven flyway


    【解决方案1】:

    不,这是不可能的。你可以做的是创建两个不同的文件夹,在你执行 da 命令运行 Flyway 的那一刻,你传递一个参数来说明 Flyway 应该读取的女巫文件夹。

    【讨论】:

      【解决方案2】:

      我通过为我想要执行的那些脚本定义文件名模式解决了我的问题,然后将它们复制到 flyway 将查找迁移的特定文件夹。

      例如,如果文件名模式为**__pattern**.sql,则配置为:

      <plugin>
          <artifactId>maven-antrun-plugin</artifactId>
          <version>1.8</version>
          <executions>
              <execution>
                  <id>copy-flyway-scripts</id>
                  <phase>compile</phase>
                  <configuration>
                      <target name="copy-flyway-scripts">
                          <echo>Copying SQL scripts</echo>
                          <copy todir="./target/flyway">
                              <fileset dir="./src/main/resources/oracle" >
                                  <include name="**__pattern**.sql"/>
                              </fileset>
                          </copy>
                      </target>
                  </configuration>
                  <goals>
                      <goal>run</goal>
                  </goals>
              </execution>
          </executions>
      </plugin>
      <plugin>
          <groupId>org.flywaydb</groupId>
          <artifactId>flyway-maven-plugin</artifactId>  
          <version>3.0</version>  
          <configuration>
              <driver>${db-driver-name}</driver>
              <url>${db-url}</url>
              <user>${db-user-name}</user>
              <password>${db-user-password}</password>
              <locations>
                  <location>filesystem:./target/flyway</location>
              </locations>
              <schemas>
                  <schema>SCHEMA</schema>
              </schemas>
          </configuration>
      </plugin>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-11-11
        • 2016-04-27
        • 2021-05-31
        • 2018-05-25
        • 2021-12-02
        • 1970-01-01
        • 2018-02-28
        • 2015-01-03
        相关资源
        最近更新 更多