Instruction file imported from Banquished/FastAPI-service (
.github/instructions/migrations.instructions.md). Copyright stays with the author.
Migrations
- Import every SQLAlchemy model into
alembic/env.pybefore assigning or usingtarget_metadata. - Generate migrations from the intended model metadata, then inspect every upgrade and downgrade operation.
- Never run migrations automatically during application startup.
- Keep migrations deterministic and independent of runtime request handling.
- Avoid destructive or irreversible schema operations without an explicit migration and rollout plan.
- Validate migrations against a disposable database with
alembic upgrade headandalembic check.
When changing an existing populated schema, account for compatibility, data backfill, deployment ordering, rollback limitations, and the period in which old and new application versions may coexist.