Right now we use SQLModel.metadata.create_all() to set up the database. This works for creating new tables but it cannot modify existing ones. If someone adds a column to a model, create_all() will silently skip the change because the table already exists.
With new models coming in #544, we need a proper way to handle schema changes.
What needs to happen
- Add
alembic as a dependency
- Set up
alembic.ini and alembic/env.py wired to our existing config.py
- Write the first migration covering
Template and FormSubmission
- Replace
create_all() in init_db.py with alembic upgrade head
- Keep
create_all() in tests (in-memory SQLite, no migration overhead)
- Add
alembic check to CI so missing migrations fail the build
- Add
make migrate and make migration to the Makefile
Related
Part of #541, prerequisite for #544
Right now we use
SQLModel.metadata.create_all()to set up the database. This works for creating new tables but it cannot modify existing ones. If someone adds a column to a model,create_all()will silently skip the change because the table already exists.With new models coming in #544, we need a proper way to handle schema changes.
What needs to happen
alembicas a dependencyalembic.iniandalembic/env.pywired to our existingconfig.pyTemplateandFormSubmissioncreate_all()ininit_db.pywithalembic upgrade headcreate_all()in tests (in-memory SQLite, no migration overhead)alembic checkto CI so missing migrations fail the buildmake migrateandmake migrationto the MakefileRelated
Part of #541, prerequisite for #544