postgress和springboot中flywaydb迁移后外键不正确

问题描述 投票:0回答:1

我有 4 个租户 - dev1、dev2、dev3、dev4 我正在使用 spring boot、postgress 数据库和 Flywaydb 迁移到数据库版本,并在新租户注册时自动创建。 基本代码:https://github.com/AnarSultanov/examples/tree/master/schema-based-multi-tenancy

https://sultanov.dev/blog/schema-based-multi-tenancy-with-spring-data/

在我的sql脚本中我添加了外键,但是在flyway db初始化并且应用程序运行之后 每个模式/表的所有外键都引用所有模式

一个模式可以访问另一个外键表引用

enter image description here

enter image description here

外键正在增加现有租户的数量

enter image description here 这将通过从用户/租户表循环生成模式 成功运行 Fly migrate 后,外键将创建多次(与存在的架构计数相同)。

sql postgresql spring-boot multi-tenant flyway
1个回答
0
投票

您可以尝试使所有对表的引用都具有引用中的架构。 Flyway 允许您指定占位符来帮助处理多租户模式:https://www.red-gate.com/blog/handling-multiple-schemas-in-the-same-database-with-flyway

CREATE TABLE ${flyway:defaultSchema}.MyTable (id INT);

除此之外 - 目前尚不清楚确切的问题是什么 - 您能否在可以共享的小型复制品中重新创建它?

© www.soinside.com 2019 - 2024. All rights reserved.