尝试将 flyway 用于多个数据库实例

Try to use flyway for multiple DB instances

运行 Maven flyway-plugin

mvn flyway:migrate

使用此配置:

    <plugin>
      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-maven-plugin</artifactId>
      <version>4.0.3</version>
      <configuration>
        <driver>com.mysql.jdbc</driver>
        <url>jdbc:mysql://localhost:3306/schema2?createDatabaseIfNotExist=true</url>
        <user>root</user>
        <password>root</password>
      </configuration>
    </plugin>

我尝试像在这个解决方案中一样创建执行次数: How to use Flyway configuration to handle multiple databases

从一次执行开始:

    <plugin>
      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-maven-plugin</artifactId>
      <version>4.0.3</version>
      <executions>
        <execution>
          <id>migrate-database</id>
          <phase>compile</phase>
          <goals>
            <goal>migrate</goal>
          </goals>
          <configuration>
            <driver>com.mysql.jdbc</driver>
            <url>jdbc:mysql://localhost:3306/schema2?createDatabaseIfNotExist=true</url>
            <user>root</user>
            <password>root</password>
          </configuration>
        </execution>
      </executions>
    </plugin>

查看异常:

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

flyway好像看不到里面的配置 (有趣的是,在我之前提到的 link 中,它有效)

请帮助通过 maven 创建 flyway multyDB 集成。

驱动程序的 FQN 不正确,应该是 com.mysql.jdbc.Driver 或者您也可以简单地删除它,因为它会从 URL.

中自动检测到

您还需要通过添加

将驱动程序添加为插件的依赖项
<plugin>
    ...
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.39</version>
        </dependency>
    </dependencies>
</plugin>

当您的 Maven 插件配置中有多个(或只有一个)<execution> 并尝试从命令行 运行 执行特定操作时,您需要通过执行指定执行 id 就像你的情况一样

mvn flyway:migrate@migrate-database

另请参阅:How to execute maven plugin execution directly from command line?

最后,如果您希望某个特定的执行成为默认执行,您可以为其指定执行 ID default-cli,如 these maven docs 中所述。然后你可以简单地 运行 mvn flyway:migrate.