gpt4 book ai didi

java - 用于多个数据库连接的 Flyway (Java/Spring)

转载 作者:太空宇宙 更新时间:2023-11-04 09:23:08 26 4
gpt4 key购买 nike

我的 Java/Springboot 2 应用程序从一个数据库读取并写入第二个数据库。代码工作正常(两个不同的数据源、实体工厂、目录等),但我不知道如何告诉 Flyway 使用脚本 A 来更新 DB A 和脚本 B 来更新 DB B。

谷歌搜索已经找到了不同环境中的不同单一数据库和同一类型的多个数据库的结果,但我还没有找到正确的搜索词来找到如何同时与具有不同模式的两个不同数据库进行对话的答案。

最佳答案

如 Spring Boot 文档中所述

https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-execute-flyway-database-migrations-on-startup

You can also add a special {vendor} placeholder to use vendor-specific scripts. Assume the following:

 spring.flyway.locations=classpath:db/migration/\{vendor} 

Rather than using db/migration, the preceding configuration sets the folder to use according to the type of the database (such as db/migration/mysql for MySQL). The list of supported databases is available in DatabaseDriver.

您可以只更改flyway的默认位置

spring.flyway.locations=classpath:db/migration/vendor1, classpath:db/migration/vendor2

Spring Boot 调用 Flyway.migrate() 来执行数据库迁移。如果您想要更多控制,请提供一个实现 FlywayMigrationStrategy 的 @Bean。

关于java - 用于多个数据库连接的 Flyway (Java/Spring),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58065968/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com