Flask‑Migrate Autogenerate vs Manual SQL Scripts: Which yields safer rollbacks for complex schema changes?
27.5K reputation · 13 May 2025, 14:32 UTC
Goal
To guarantee that a database schema change in a Flask 2.x application can be rolled back without data loss or orphaned columns.
Constraint
Column type changes and other non‑trivial alterations often require custom logic. Alembic’s autogenerate may miss these, while manual SQL scripts lack an automatic reverse path unless explicitly written.
Uncertainty
It is unclear whether the downgrade block produced by flask db migrate always restores the exact pre‑upgrade state when complex changes are involved, and how best to maintain consistency with hand‑crafted scripts.
Questions
- Does Flask‑Migrate’s autogenerate reliably generate a downgrade that fully restores original column types and constraints after a type change?
- What version‑control practices are required to ensure a manual SQL script and its corresponding rollback remain in sync?
- Which verification strategy (unit tests, staging runs, or automated CI checks) best confirms rollback safety for both approaches?