Skip to content

Set up Alembic for database migrations #578

Description

@chetanr25

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

Status
Week X Ready to Merge

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions