Note
Hasura + postgreSQLの構成でtextをuuidに変更するマイグレーションを行いたい。
まずはマイグレーションファイルを生成する。
hasura migrate create text_to_uuid
hasura/migrations
にファイルが生成されるのでそこにマイグレーション処理を記述していく。
あとは基本的にPostgresqlのSQLの記述を行なっていくのみ
up.sql
とdown.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
を実行する