我的 master-chaneglog.yaml 如下所示,
databaseChangeLog:
- include:
relativeToChangelogFile: true
file: db_ver_1.0/scripts.yaml
scripts.yaml 如下所示,
databaseChangeLog:
- include:
relativeToChangelogFile: true
file: tables/001_table1_create.sql
- include:
relativeToChangelogFile: true
file: tables/002_table2_create.sql
- include:
relativeToChangelogFile: true
file: functions/001_function1.sql
- include:
relativeToChangelogFile: true
file: functions/002_function2.sql
对于函数,我设置了 runOnChange:true,因此当我放入更改时,仍然可以执行相同的更改集。
但是对于表,假设 table1 仅在 Dev env 中创建,然后我通过创建一个包含 ALTER TABLE 语句的新变更集向其中添加一列,如下所示,
databaseChangeLog:
- include:
relativeToChangelogFile: true
file: tables/001_table1_create.sql
- include:
relativeToChangelogFile: true
file: tables/002_table2_create.sql
- include:
relativeToChangelogFile: true
file: functions/001_function1.sql
- include:
relativeToChangelogFile: true
file: functions/002_function2.sql
- include:
relativeToChangelogFile: true
file: tables/003_table1_alter.sql
随着时间的推移,scripts.yaml 中列出的变更集可能会非常长,并且某些变更集实际上可以合并为一个(假设变更集仅部署到 Dev env 中)。
我的问题是,当我将这些更改部署到 T/prod 环境中时,对于上述场景,如果我只想拥有一个 001_table1_create.sql,而不是 001_table1_create.sql + 003_table1_alter.sql,最好的方法是什么?我应该创建一个 db_ver_2.0/scripts.yaml,并从 master-chaneglog.yaml 中删除 db_ver_1.0/scripts.yaml,如下所示,
databaseChangeLog:
- include:
relativeToChangelogFile: true
file: db_ver_2.0/scripts.yaml
其中db_ver_2.0/scripts.yaml只有tables/001_table1_create.sql(并且该文件将具有我添加的附加列)?
databaseChangeLog:
- include:
relativeToChangelogFile: true
file: tables/001_table1_create.sql #this file has the additional column
- include:
relativeToChangelogFile: true
file: tables/002_table2_create.sql
- include:
relativeToChangelogFile: true
file: functions/001_function1.sql
- include:
relativeToChangelogFile: true
file: functions/002_function2.sql