生产环境中的数据库迁移
Running database schema migrations safely in production requires isolating schema DDL operations from the application container lifecycle.
Safe Migration Workflow
- Pre-Deployment Check: Test migration scripts in a staging environment matching production TimescaleDB versions:
alembic currentalembic heads
- Execute Migrations Before 状态码 Rollout:
触发一次性迁移 Profile 容器:
docker compose --profile migrate run --rm fonrex-migrate
- Deploy New API Containers:
Once
alembic upgrade headfinishes successfully, update your API application image:docker compose up -d fonrex-api - Rollback Strategy:
If a migration fails, revert to the previous migration revision:
docker compose --profile migrate run --rm fonrex-migrate alembic downgrade -1