Skip to content

Conversation

@TkymHrt
Copy link
Member

@TkymHrt TkymHrt commented Sep 7, 2025

対応Issue

  • デプロイ時に不整合が発生したため

概要

本番で手動作成された events テーブルを正式なマイグレーションとして管理下に置き、以後の環境差異を防止。
併せて Hasura 適用順序を migrate → metadata に変更し一時的な不整合警告の発生を回避。

実装詳細

  • 追加: 1757258450288_ensure_events_table
    • up.sql: CREATE TABLE IF NOT EXISTS public.events (...)
    • down.sql: DROP TABLE IF EXISTS public.events;
    • 既存マイグレーションに後追い追記せず、新規マイグレーションとして追加
  • 修正: Makefile
    • db-apply / db-apply-prod の順序を
      • (旧) metadata apply → migrate → reload
      • (新) migrate → metadata apply → reload
    • コメント追加で意図を明示

画面スクリーンショット等

(不要 / なし)

テスト項目

  • ローカル: make runhasura migrate status で新マイグレーションが Applied
  • GraphQL { events { id surveyUrl isSurveyActive } } が 200 / エラーなし
  • 既に events が存在する環境(本番)でも再適用時エラーが出ない(IF NOT EXISTS
  • 他既存テーブルに影響がない(差分なし)
  • Makefile の順序変更で初回起動時に metadata 不整合が出ない

@TkymHrt TkymHrt marked this pull request as ready for review September 7, 2025 15:40
@github-actions github-actions bot added backend bug Something isn't working labels Sep 7, 2025
@TkymHrt TkymHrt requested a review from hikahana September 7, 2025 15:41
docker compose exec api hasura metadata apply
docker compose exec api hasura metadata reload

db-export:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo
これもしかしてだけどdb-exportのmakeコマンドいらない説ありそう。
先、migrateでup.sql down.sqlが作成されるから今後はmigrateのバージョン管理だけで完結しそう。
一応コメントアウト対応とかがいいかも!

down:
docker compose down

# Apply database migrations first, then metadata to avoid temporary inconsistencies
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これいらなーい

docker compose exec api hasura metadata export
docker compose exec api hasura migrate create "auto" --from-server --database-name default

# Production apply order aligned with best practice (migrations first)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これもいらなーい

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants