Flyway数据库迁移到多个模式

时间:2014-12-18 12:10:37

标签: java database maven migration flyway

我为我的多租户应用程序设置了一个迁移脚本。问题是。它只生成我在参数上指定的第一个租户/架构的脚本。这是我的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;

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

的命令

它只生成第一个租户的表格,即tenant3。

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

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:2)

请在

中找到flyway的推荐信息

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

希望这有帮助。

相关问题