云原生声明式数据库结构迁移工具 - SchemaHero( 四 )

修改后重新应用该文件:
$ kubectl apply -f schedule-table.yaml应用后,同样查看下该 migration 对象:
$ kubectl schemahero get migrations -n schemahero-tutorialIDDATABASETABLEPLANNEDEXECUTEDAPPROVEDREJECTEDa9626a8airlinedbschedule9m30s7m58s8m0seaa36efairlinedbairport4h4h4hfa32022airlinedbschedule5s可以看到多了一个新的 migration 对象处于 pending 状态 。同样使用 describe 命令查看该 migration 的详细信息 。
$ kubectl schemahero -n schemahero-tutorial describe migration fa32022Migration Name: fa32022Generated DDL Statement (generated at 2020-06-06T14:56:04-07:00):alter table "schedule" alter column "departure_time" type time, alter column "departure_time" drop not null;alter table "schedule" alter column "arrival_time" type time, alter column "arrival_time" drop not null;alter table "schedule" add column "duration" integer;To apply this migration:kubectl schemahero -n schemahero-tutorial approve migration fa32022To recalculate this migration against the current schema:kubectl schemahero -n schemahero-tutorial recalculate migration fa32022To deny and cancel this migration:kubectl schemahero -n schemahero-tutorialreject migration fa32022上面的信息中可以看到该次迁移生成的 DDL 语句包括 3 个不同的语句, SchemaHero 将我们刚刚部署的 YAML 与实际的数据库结构进行了比较,并生成了上述命令 。
同样校验下迁移语句没问题过后我们就可以直接批准该次迁移 。
$ kubectl schemahero -n schemahero-tutorial approve migration fa32022Migration fa32022 approved正常批准后表结构就变更成功了 。
到这里我们就基本上了解了 SchemaHero 的基础知识,当然 SchemaHero 还有需要功能没有介绍,可以查看官方文档
https://schemahero.io/docs/ 了解更多相关信息 。
Git 仓库:
https://github.com/schemahero/schemahero
原文链接:
https://mp.weixin.qq.com/s?__biz=MzU4MjQ0MTU4Ng==&mid=2247502093&idx=1&sn=6475044141882963eabbfca39421f3ab




推荐阅读