$ kubectl schemahero get migrations -n schemahero-tutorialIDDATABASETABLEPLANNED EXECUTED APPROVED REJECTED eaa36ef airlinedbairport11s如果没有找到资源,请等待几秒钟,然后重试,SchemaHero Operator 必须在 migration 可用之前完成 plan 阶段 。
在批准该迁移之前,我们可以查看附加到 migration 对象上面生成的 SQL 语句 。从上一个命令的输出中获取 ID,然后运行 describe migration 即可:
$ kubectl schemahero describe migration eaa36ef -n schemahero-tutorialMigration Name: eaa36ef Generated DDL Statement (generated at 2020-06-06T10:41:04-07:00):create table "airport" ("code" character (4), "name" character varying (255) not null, primary key ("code")); To apply this migration:kubectl schemahero -n schemahero-tutorial approve migration eaa36ef To recalculate this migration against the current schema:kubectl schemahero -n schemahero-tutorial recalculate migration eaa36ef To deny and cancel this migration:kubectl schemahero -n schemahero-tutorial reject migration eaa36ef在输出的顶部,生成的 DDL 语句是计划的迁移,这是 SchemaHero 将运行以应用此迁移的确切 SQL 语句 。
在后面, SchemaHero 为后续步骤提供了 3 个命令:
- apply :运行此命令将接受 SQL 语句, SchemaHero 将对数据库执行它 。
- recalculate SchemaHero SchemaHero
- reject :运行此命令将拒绝迁移并且不执行它 。
$ kubectl schemahero -n schemahero-tutorial approve migration eaa36efMigration eaa36ef approved我们可以再次运行 get migrations 来查看迁移的状态:$ kubectl schemahero get migrations -n schemahero-tutorialIDDATABASETABLEPLANNEDEXECUTEDAPPROVEDREJECTEDeaa36efairlinedbairport9m38s38s52s上面的信息表明迁移计划在 9 分 38 秒前,在 52 秒前批准,在 38 秒前执行 。现在我们在 Beekeeper Studio 工具中单击左侧导航中 Tables & Views 标题上的刷新按钮,正常我们现在可以在 public 下看到 airport 表,点开该表,可以看到表中的列数据 。

文章插图
修改表接下来我们来部署一个 table 对象然后来修改表结构 。
和前面一样,首先我们创建一个 schedule 表,结构如下所示:

文章插图
定义一个对应的 Table 表对象,内容如下所示:
# schedule-table.yamlapiVersion: schemas.schemahero.io/v1alpha4kind: Tablemetadata:name: schedulenamespace: schemahero-tutorialspec:database: airlinedbname: scheduleschema:postgres:primaryKey: [flight_num]columns:- name: flight_numtype: int- name: origintype: char(4)constraints:notNull: true- name: destinationtype: char(4)constraints:notNull: true- name: departure_timetype: timeconstraints:notNull: true- name: arrival_timetype: timeconstraints:notNull: true直接应用上面的资源清单即可:$ kubectl apply -f schedule-table.yaml -n schemahero-tutorial$ kubectl schemahero get migrations -n schemahero-tutorial当 schedule 迁移准备好时,它将显示在输出中:IDDATABASETABLEPLANNED EXECUTED APPROVED REJECTED a9626a8 airlinedb schedule 21s eaa36ef airlinedb airport4h3h3h同样可以通过 describe 查看对应的 SQL 语句过后,如果是安全的,则可以审批该变更 。$ kubectl schemahero -n schemahero-tutorial approve migration a9626a8批准后可以在 Beekeeper Studio 中查看是否有 schedule 表了 。
文章插图
现在让我们对这个表结构做一些更改:
- 使 departure_time 和 arrival_time 列可以为空
- 添加一个名为 duration 的新列
apiVersion: schemas.schemahero.io/v1alpha4kind: Tablemetadata:name: schedulenamespace: schemahero-tutorialspec:database: airlinedbname: scheduleschema:postgres:primaryKey: [flight_num]columns:- name: flight_numtype: int- name: origintype: char(4)constraints:notNull: true- name: destinationtype: char(4)constraints:notNull: true- name: departure_timetype: time- name: arrival_timetype: time- name: durationtype: int
推荐阅读
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 在.Net 7原生支持Webp和Heif格式文件生成
- Intel|Intel全新加速显卡Arctic Sound-M出货:8路4K云游戏无压力
- 奇瑞风云二的车到底好不好 奇瑞风云2怎么样
- 江波|精选诗词|?一路须随云露冷,只身欲返月明空
- 岳云鹏数30数字游戏 数30怎么玩必赢
- 名将赵云之死 赵云怎么死的
- 新手如何看大盘? 如何看大盘
- 云吞馅的做法和配料
- 为什么紫云英成为了矿工 为什么紫云英成为了“矿工”
- 印度法院传唤马云,究竟发生了什么事情? 马云近几天出什么事了
