维护flyway中不同文件夹的sql脚本执行顺序

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

作为项目设置的一部分,我正在执行 flyway 脚本

在目录中有2个文件夹DDL和DML,为了设置,我首先运行DDL文件夹中的所有脚本,然后清除飞行历史表,然后运行DML文件夹中的所有脚本。

问题:如果在不清除 flyway 历史表的情况下运行 DML 文件夹中的脚本,它会出错并说文件已被修改。

我想保留脚本执行的历史记录。我怎样才能做到这一点?

错误:

ERROR: Validate failed: Migrations have failed validation Migration checksum mismatch for migration version 2 -> Applied to database : 1962665489 -> Resolved locally    : -223568245 Either revert the changes to the migration, or run repair to update the schema history.

错误是有道理的,因为存在具有相同版本号的文件。

期望的结果:

flyway_schema_history 表

安装排名 版本 描述 类型 剧本 校验和 安装者 installed_on 执行时间 成功
1 1 DDL 脚本 1 SQL V1__DDL_Script_1.sql 885232507 postgres 43:06.9 30 真实
2 2 DDL 脚本 2 SQL V2__DDL_Script_2.sql 1962665489 postgres 43:07.0 22 真实
3 3 DDL 脚本 3 SQL V3__DDL_Script_3.sql 1491548605 postgres 43:07.0 28 真实
4 1 DML 脚本 1 SQL V1__DML_Script_1.sql 9491548656 postgres 43:07.0 28 真实
5 2 DML 脚本 2 SQL V2__DML_Script_2.sql 1436548605 postgres 43:07.0 24 真实
6 3 DML 脚本 3 SQL V3__DML_Script_3.sql 2691548605 postgres 43:07.0 28 真实

文件夹中的数据看起来像这样:

DDL

-- V1__DDL_Script_1.sql

-- V2__DDL_Script_2.sql

-- V3__DDL_Script_3.sql

DML

-- V1__DML_Script_1.sql

-- V2__DML_Script_2.sql

-- V3__DML_Script_3.sql

sql database postgresql liquibase flyway
1个回答
0
投票

我认为你做不到,不能有两个相同版本的文件。我的意见是使用以下两种方式之一:

1)使它们按顺序排列:

DDL

-- V1__DDL_Script_1.sql

-- V2__DDL_Script_2.sql

-- V3__DDL_Script_3.sql

DML

-- V4__DML_Script_1.sql

-- V5__DML_Script_2.sql

-- V6__DML_Script_3.sql

2) 添加次要版本

DDL

-- V1_1__DDL_Script_1.sql

-- V1_2__DDL_Script_2.sql

-- V1_3__DDL_Script_3.sql

DML

-- V2_1__DML_Script_1.sql

-- V2_2__DML_Script_2.sql

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