feat(backend): docker 起動時に初回マイグレーションを自動実行#28
Open
naohanpen wants to merge 2 commits into
Open
Conversation
- app コンテナの起動コマンドを `db:migrate && dev` に変更し、 初回 docker compose up 時にスキーマが自動で DB に適用されるようにする - スキーマからマイグレーション SQL を生成しコミット - README から手動 db:push 手順を削除し、自動マイグレーションの流れに更新 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
自動マイグレーション化に合わせてクイックスタートを更新 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
backend を
docker compose upしたときに、初回起動でスキーマが自動で DB に反映されるようにしました。これまで必要だった手動のdocker compose exec app npm run db:pushが不要になります。変更内容
docker-compose.yml:appサービスの起動コマンドをsh -c "npm run db:migrate && npm run dev"に変更。DB が healthy になってからマイグレーションを適用し、dev サーバを起動します。drizzle/:src/db/schema.tsから生成したマイグレーション SQL(users/messages)を追加・コミット。README.md: 手動db:push手順を削除し、自動マイグレーション前提の流れに更新。スキーマ変更時はnpm run db:generateしてから再起動する手順を明記。補足
db:migrateは適用済みを drizzle が記録するため、2回目以降の起動では差分のみ適用され、何度起動しても安全です(=「初回だけ実際にマイグレーションが走る」挙動)。db:push(直反映)ではなくdb:migrate(生成済みマイグレーション適用)を採用し、変更履歴がdrizzle/に残る運用にしています。動作確認
docker compose configが通ることを確認docker compose up --buildでの初回マイグレーション適用(レビュー時に確認)🤖 Generated with Claude Code