How to use Flyway configuration to handle multiple databases How to use Flyway configuration to handle multiple databases database database

How to use Flyway configuration to handle multiple databases


You can specify multiple executions for a single plugin with different configurations:

 <plugin>    <groupId>org.flywaydb</groupId>    <artifactId>flyway-maven-plugin</artifactId>    <version>3.0</version>    <executions>        <execution>            <id>first-execution</id>            <phase>compile</phase> <!--whatever phase you need-->            <goals>                <goal>migrate</goal>            </goals>            <configuration>                <url>jdbc:mysql://localhost:3306/schema2</url>                <user>root</user>                <password>root</password>                <locations>                    <location>                        filesystem:/path/to/migrations/folder                    </location>                </locations>            </configuration>        </execution>        <execution>            <id>second-execution</id>            <phase>compile</phase> <!--whatever phase you need-->            <goals>                <goal>migrate</goal>            </goals>            <configuration>                <url>jdbc:mysql://localhost:3306/schema1</url>                <user>root</user>                <password>root</password>                <locations>                    <location>                        filesystem:/path/to/other/migrations/folder                    </location>                </locations>            </configuration>        </execution>    </executions>    <dependencies>        <dependency>            <groupId>mysql</groupId>            <artifactId>mysql-connector-java</artifactId>            <version>5.1.21</version>        </dependency>    </dependencies></plugin>

You can use 'location' property to define migrations you want to run for each schema, just like it's done in example above. The location type is determined by its prefix. Unprefixed locations or locations starting with classpath: point to a package on the classpath and may contain both sql and java-based migrations. Locations starting with filesystem: point to a directory on the filesystem and may only contain sql migrations.