Maven Flyway Plugin, Teams Edition, undo with cherryPick

Viewed 124

I have a Maven project with the Flyway Plugin. This Project should test the function of Flyway with a PostgreSQL Database. I got the Testdrive for the Teams Edition. I am also able to execute every Flyway-Goal also undo. The commands I execute looks like following mvn flyway:undo and it works fine.
What i want to execute: mvn flyway:undo -cherryPick=2 or mvn flyway:undo -cherryPick=1.2

Anyway when i want to add cherryPick in my pom.xml file with:

<configuration>
   <cherryPick>2.0</cherryPick>
</configuration>

I use: apache-maven 3.6.1

I got following Error, no matter which command i try. Error also occurs when executing Flyway-Goals for Community Edition.

...
[ERROR] Failed to execute goal org.flywaydb.enterprise:flyway-maven-plugin:8.5.10:info (default-cli) on project flyway-demo: org.flywaydb.core.api.FlywayException: No matching migrations found for pattern: 2.0 -> [Help 1
]
...

Here my pom.xml file:

    <dependencies>
        <dependency>
            <groupId>org.flywaydb</groupId>
            <artifactId>flyway-core</artifactId>
            <version>8.5.10</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>sql-maven-plugin</artifactId>
                <version>1.5</version>
            </plugin>
            <plugin>
                <groupId>org.flywaydb.enterprise</groupId>
                <artifactId>flyway-maven-plugin</artifactId>
                <version>8.5.10</version>
                <configuration>
                    <licenseKey>...</licenseKey>
                    <url>Database-url</url>
                    <user>user</user>
                    <password>pw</password>
                    <driver>Database.Driver</driver>
                    <locations>
                        <location>filesystem:src/main/resources/db/migration</location>
                    </locations>
                    <outOfOrder>true</outOfOrder>
                    <cherryPick>1.2</cherryPick>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.postgresql</groupId>
                        <artifactId>postgresql</artifactId>
                        <version>42.2.6</version>
                    </dependency>
                    <dependency>
                        <groupId>postgresql</groupId>
                        <artifactId>postgresql</artifactId>
                        <version>9.1-901-1.jdbc4</version>
                    </dependency>
                </dependencies>

            </plugin>
        </plugins>
    </build>

</project>

My directory for the SQL-Migrations: src-diretory for migration

I also tried to name the versions like: V0__C..., V1__A..,U0__D.., usw

Can someone help me out here? I look also already alot on https://flywaydb.org/documentation/configuration/parameters/ but found nothing...

3 Answers

The error you're getting indicates that you have no migration file for V2.0: No matching migrations found for pattern: 2.0

If i look at your image, the migration files you have available are V1.0 to V1.3. Any of those values should work.

If you want to provide the cherryPick value via the Maven commandline, you have to provide them like so: mvn flyway:undo -Dflyway.cherryPick=1.3

See: https://flywaydb.org/documentation/usage/maven/

You can also check if your provided location for the migration files is correct by adding the following option:

<configuration>
    <failOnMissingLocations>true</failOnMissingLocations>
</configuration>

References:

thanks for your answer. i figured out a similar way, but i am still not satisfied.
Currently it works for me with a placeholder variable in my pom.xml script.

The missing Pattern i understand now. I watched out for this, that the versionnumbers are fitting. So these Problem is solved.

I add these 2 Parts in my pom.xml file:

<properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <flyway.cherryPick>${CHERRY_PICK_VERSION}</flyway.cherryPick>
</properties>

and

<configuration>
    <cherryPick>{flyway.cherryPick}</cherryPick>
</configuration>

Then i can pass mvn the value of the cherryPick. My Command looks like that: mvn -DCHERRY_PICK_VERSION="2" flyway:undo , but i dont want to give maven the value to set it fix in the pom.xml.

I want to pass the cherryPick versions to flyway. So i dont have to pass in every command my CHERRY_PICK_VERSION when i want just mvn flyway:info for example. The command with using cherrPick should like that then: mvn flyway:undo -Dflyway.cherryPick=2. Both commands should be possible, with and without the flag.

I tried already to cut the cherryPick configurations out of my pom.xml and tried the commands: mvn flyway:undo -Dflyway.cherryPick=2 & mvn -Dflyway.cherryPick=2 flyway:undo
PS: Versionnumers are 0,1,2,3 now.

Both occurs following Error

[ERROR] Unknown lifecycle phase ".cherryPick=2". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version>]:<goal>. Available life
cycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-te
st-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post
-site, site-deploy. -> [Help 1]

In the flyway-commandwindow itselfs works perfectly fine. But i want it to work with mvn-command too.
I dont want that u need to download extra Flyway, for the command-window. Instead i want to download it with a plugin for my Mavenproject and execute the flyway goals with Maven.

I was able to fix it! Dont need any support anymore! Thanks:)

Related