java Flyway 数据库迁移到多个模式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27546313/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 11:57:59  来源:igfitidea点击:

Flyway database migration to multiple schemas

javadatabasemavenmigrationflyway

提问by user962206

I've set up a migration script for my multi-tenant application. the problem was. it's only generating the scripts for the first tenant/schema I've specified on the parameter. Here's my sql script

我已经为我的多租户应用程序设置了一个迁移脚本。问题是。它只为我在参数中指定的第一个租户/模式生成脚本。这是我的 sql 脚本

drop table if exists ADMIN_ACCOUNT cascade;

drop table if exists PERSON_NAME cascade;

drop table if exists USER_ACCOUNT cascade;

create table ADMIN_ACCOUNT (
    id int8 not null,
    created_date timestamp,
    PASSWORD varchar(255),
    USERNAME varchar(255),
    membershipType varchar(255),
    NAME_ID int8,
    primary key (id)
);

create table PERSON_NAME (
    id int8 not null,
    created_date timestamp,
    FIRST_NAME varchar(255),
    LAST_NAME varchar(255),
    MIDDLE_NAME varchar(255),
    account_id int8,
    primary key (id)
);

create table USER_ACCOUNT (
    id int8 not null,
    created_date timestamp,
    PASSWORD varchar(255),
    USERNAME varchar(255),
    ROLE varchar(255),
    TENANT_CODE varchar(255),
    NAME_ID int8,
    primary key (id)
);

alter table ADMIN_ACCOUNT
add constraint FK_fil1krx8k0osj713tg44ia0vu
foreign key (NAME_ID)
references PERSON_NAME;

alter table PERSON_NAME
add constraint FK_hc1g7pa0rseytw9o1pcuo0mpw
foreign key (account_id)
references USER_ACCOUNT;

alter table USER_ACCOUNT
add constraint FK_ib2pk4at20vxm3onaoro6ry2r
foreign key (NAME_ID)
references PERSON_NAME;

Here's the command I have entered to flyway mvn compile flyway:migrate -Dflyway.schemas=tenant3,tenant4,tenant5 -Dflyway.baselineOnMigrate=true

这是我输入到 flyway 的命令 mvn compile flyway:migrate -Dflyway.schemas=tenant3,tenant4,tenant5 -Dflyway.baselineOnMigrate=true

It's only generating the tables for the first tenant which is tenant3.

它只为第一个租户(即租户 3)生成表。

Is this a bug? or am Missing something?

这是一个错误吗?还是遗漏了什么?

回答by Axel Fontaine

To create multiple identical schemas you have to invoke Flyway once for each schema, with the flyway.schemas property set the to correct value. Flyway will then set the correct schema as the default one, letting you run your migration scripts unchanged (as long as you don't prefix the object names).

要创建多个相同的模式,您必须为每个模式调用一次 Flyway,并将 flyway.schemas 属性设置为正确的值。Flyway 然后会将正确的架构设置为默认架构,让您原样运行迁移脚本(只要您不为对象名称添加前缀)。

回答by dopeddude

Please find recommendations from flyway as in

请从 Flyway 中找到建议,如

http://flywaydb.org/documentation/faq.html#multiple-schemas

http://flywaydb.org/documentation/faq.html#multiple-schemas

Hope this helps.

希望这可以帮助。