Flyway 位置 - 指向单个 sql 脚本
Flyway location - Point to single sql script
我在这样的文件夹中有脚本:
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
。
我读了这个 ,但我发现我不能为迁移指定单个 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]
当我把<locations>
改成
<locations>
<location>filesystem:oracle</location>
</locations>
flyway 执行所有脚本。
不,这不可能。你可以做的是创建两个不同的文件夹,在你对 运行 Flyway 执行 da 命令的那一刻,你传递一个参数来说明 文件夹 Flyway 应该读取。
我通过为我想执行的那些脚本定义文件名模式解决了我的问题,然后将它们复制到 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>
我在这样的文件夹中有脚本:
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
。
我读了这个
这可能吗?我收到以下错误:
[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]
当我把<locations>
改成
<locations>
<location>filesystem:oracle</location>
</locations>
flyway 执行所有脚本。
不,这不可能。你可以做的是创建两个不同的文件夹,在你对 运行 Flyway 执行 da 命令的那一刻,你传递一个参数来说明 文件夹 Flyway 应该读取。
我通过为我想执行的那些脚本定义文件名模式解决了我的问题,然后将它们复制到 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>