Note

Hasura + postgreSQLの構成でtextをuuidに変更するマイグレーションを行いたい。

まずはマイグレーションファイルを生成する。

hasura migrate create text_to_uuid

hasura/migrationsにファイルが生成されるのでそこにマイグレーション処理を記述していく。 あとは基本的にPostgresqlSQLの記述を行なっていくのみ

up.sqldown.sqlを記述

-- id_uuidを追加
alter table "public"."Table" add column "id_uuid" uuid;
 
-- id_uuidにidの値を追加
update "public"."Table" set 
  "id_uuid" = cast("id" as uuid),
 
-- idを削除
alter table "public"."Table" drop column "id";
 
-- id_uuidをidに変更
alter table "public"."Table" rename column "id_uuid" to "id";

hasura migrate applyを実行する