首页 > 解决方案 > 如何使用 Spring、Quarkus、Flyway、Hibernate、多租户在所有模式中运行迁移?

问题描述

早上好,我正在尝试使用 flyway、hibernate、panache 和多租户建立一个 QUARKUS 项目。但是脚本只在第一个模式上运行一次,有人知道如何在其他模式上运行吗?

应用程序.yml

 datasource:
   db-kind: postgres
   username: postgres
   password: 1234
   jdbc:
     url: jdbc:postgresql://localhost:5432/postgres
     driver: org.postgresql.Driver
 hibernate-orm:
   multitenant: SCHEMA
   dialect: org.hibernate.dialect.PostgreSQLDialect
   log:
     sql: true
 flyway:
   migrate-at-start: true
   baseline-on-migrate: true
   baseline-version: 1.0.0
   create-schemas: true
   clean-at-start: true
   schemas: maripa, bicas, rhino
   locations: db/migration/maripa, db/migration/bicas, db/migration/rhino

日志

    __  ____  __  _____   ___  __ ____  ______ 
 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ 
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \   
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/   
2021-03-09 07:41:54,213 INFO  [io.qua.fly.FlywayProcessor] (build-13) Adding application migrations in path '/home/idd_acosta/freelas/rhino/rhino-api/target/classes/db/migration/maripa/' using protocol 'file'
2021-03-09 07:41:54,844 INFO  [io.qua.arc.pro.BeanProcessor] (build-8) Found unrecommended usage of private members (use package-private instead) in application beans:
    - @Inject field br.com.rhino.user.mapper.RoleMapperImpl#permissionMapper,
    - @Inject field br.com.rhino.user.mapper.UserMapperImpl#roleMapper
2021-03-09 07:41:56,228 INFO  [org.fly.cor.int.lic.VersionPrinter] (Quarkus Main Thread) Flyway Community Edition 7.5.2 by Redgate
2021-03-09 07:41:56,348 INFO  [org.fly.cor.int.dat.bas.DatabaseType] (Quarkus Main Thread) Database: jdbc:postgresql://localhost:5432/postgres (PostgreSQL 13.1)
2021-03-09 07:41:56,380 INFO  [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped pre-schema database level objects (execution time 00:00.001s)
2021-03-09 07:41:56,426 INFO  [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped schema "maripa" (execution time 00:00.044s)
2021-03-09 07:41:56,428 INFO  [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped schema " bicas" (execution time 00:00.001s)
2021-03-09 07:41:56,430 INFO  [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped schema " rhino" (execution time 00:00.001s)
2021-03-09 07:41:56,430 INFO  [org.fly.cor.int.com.DbClean] (Quarkus Main Thread) Successfully dropped post-schema database level objects (execution time 00:00.000s)
2021-03-09 07:41:56,432 INFO  [org.fly.cor.int.lic.VersionPrinter] (Quarkus Main Thread) Flyway Community Edition 7.5.2 by Redgate
2021-03-09 07:41:56,437 INFO  [org.fly.cor.int.dat.bas.Schema] (Quarkus Main Thread) Creating schema "maripa" ...
2021-03-09 07:41:56,439 INFO  [org.fly.cor.int.dat.bas.Schema] (Quarkus Main Thread) Creating schema " bicas" ...
2021-03-09 07:41:56,439 INFO  [org.fly.cor.int.dat.bas.Schema] (Quarkus Main Thread) Creating schema " rhino" ...
2021-03-09 07:41:56,443 INFO  [org.fly.cor.int.sch.JdbcTableSchemaHistory] (Quarkus Main Thread) Creating Schema History table "maripa"."flyway_schema_history" ...
2021-03-09 07:41:56,487 INFO  [org.fly.cor.int.com.DbMigrate] (Quarkus Main Thread) Current version of schema "maripa": null
2021-03-09 07:41:56,496 INFO  [org.fly.cor.int.com.DbMigrate] (Quarkus Main Thread) Migrating schema "maripa" to version "1.0.1 - start structure maripa"
2021-03-09 07:41:56,555 INFO  [org.fly.cor.int.com.DbMigrate] (Quarkus Main Thread) Successfully applied 1 migration to schema "maripa" (execution time 00:00.078

我的路径脚本

如您所见,它仅在第一个模式中运行。如何在所有三个上运行?

Obs.:对不起,我的英语!:)

标签: springhibernatemulti-tenantflywayquarkus

解决方案


这个问题迟到了,但从Quarkus 文档看来,这是设计使然。

Flyway 的架构历史表的名称。默认情况下(单模式模式),模式历史表放置在数据源提供的连接的默认模式中。当设置 flyway.schemas 属性时(多模式模式),模式历史表被放置在列表的第一个模式中。

我想它只需要一个模式表,因为所有三个“租户”都应该保持相同的版本?


推荐阅读