matiska
matiska

Reputation: 525

Flyway location - Point to single sql script

I have scripts in folder like this:

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

I would like to keep all scripts in same folder, but ignore some of them in migration. To be precise, I would like to include just this scripts

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

Path of pom.xml is D:/dev/DatabaseSetup/oracle/pom.xml.

I read this question , but figured out that I cannot specify single sql script for migration (in accepted answer it is used classpath which points to java package).

Is it even possible? I got following error:

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

When I change <locations> to

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

flyway executes all scripts.

Upvotes: 0

Views: 3284

Answers (2)

matiska
matiska

Reputation: 525

I solved my problem by defining filename pattern for those scripts I would like to execute, then copying them to specific folder where flyway will look for migrations.

For example, if filename pattern is **__pattern**.sql, configuration would be:

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

Upvotes: 0

mvalho
mvalho

Reputation: 91

No, it's not possible. What you could do, is create two different folders, and on the moment you execute da command to run Flyway, you pass a parameter to say witch folder Flyway should read.

Upvotes: 1

Related Questions