2

I read a lot of articles (on flyway and stackoverflow) before deciding to open a question. Mostly the solutions how to setup your pom for executing multiple databases using maven and flyway surround around version 3.0 of flyway.

I have a requirement where I have to connect to multiple schemas using different user accounts and execute totally different SQL's using flyway.

I tried to setup my pom as per article, but it fails to recognize multiple execution tags and also the id. It throws the error message

[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:4.0.3:migrate (default-cli) on project Flyway_001: org.flywaydb.core.api.FlywayExce ption: Unable to connect to the database. Configure the url, user and password! -> [Help 1]

My pom looks like

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.flyway</groupId>
<artifactId>Flyway_001</artifactId>
<version>1.0-SNAPSHOT</version>
<name>${project.artifactId}-${project.version}</name>
    
<properties>
 <A.db.user>A_DB_USER</A.db.user>
  <A.db.password>*******</A.db.password>
 <A.db.schema>A_DB_SCHEMA</A.db.schema>
 <A.db.url>jdbc:oracle:blah..blah</A.db.url>
 <B.db.user>B_DB_USER</B.db.user>
 <B.db.password>*******</B.db.password>
 <B.db.schema>B_DB_SCHEMA</B.db.schema>
 <B.db.url>jdbc:oracle:blah..blah</B.db.url>
  </properties>
    
 <build>
 <plugins>
 <plugin>
   <groupId>org.flywaydb</groupId>
    <artifactId>flyway-maven-plugin</artifactId>
    <version>4.0.3</version>
    <executions>
     <execution>
      <id>flyway-A</id>
      <configuration>
    <url>${A.db.url}</url>
     <user>${A.db.user}</user>
    <password>${A.db.password}</password>
    <schemas>
    <schema>${A.db.schema}</schema>
    </schemas>
    <table>T_HUB_SCHEMA_VERSION</table>
    <baselineOnMigrate>false</baselineOnMigrate>
    <locations>
    <location>filesystem:src/main/resources/db/A</location>
    </locations>
   </configuration>
  </execution>
  <execution>
  <id>flyway-B</id>
    <configuration>
   <url>${B.db.url}</url>
    <user>${B.db.user}</user>
   <password>${B.db.password}</password>
   <schemas>
   <schema>${B.db.schema}</schema>
   </schemas>
   <table>T_HUB_SCHEMA_VERSION</table>
   <baselineOnMigrate>false</baselineOnMigrate>
   <locations>
   <location>filesystem:src/main/resources/db/B</location>
   </locations>
  </configuration>
  </execution>
  </executions>

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

Has anyone tried connecting to multiple DB's using flyway 4.0? If so will appreciate if someone can give some guidance on whats wrong with my approach.

  • Are you sure this error is because of multiple executions? The error smells like more of a general configuration problem. Can you confirm your configuration works with a single execution eg only one database? – markdsievers Oct 27 '16 at 16:59

1 Answers1

0

IDE complained about tags under execution element. Was able to get rid of the complains by specifying the goals tag like so:

<execution>
    <id>some-id</id>
    <goals>
        <goal>migrate</goal>
    </goals>
</execution>
Ville Miekk-oja
  • 18,749
  • 32
  • 70
  • 106