Workflow: Add a Migration¶
Realizes: spec_v3.md §3.8 Schema Migration.
Rule: Schema changes require an Alembic migration. Never modify tables manually.
Steps¶
- Update the SQLAlchemy model under
src/donna/tasks/(or the relevant subsystem). - Generate the migration.
- Review the generated file in
alembic/versions/. Autogenerate is not perfect — confirm it matches intent and thatdowngrade()is correct. - Ensure multi-user. Every new table needs
user_id(even if deployment is single-user today). See the precedent inalembic/versions/add_calendar_mirror_user_id.py. - Apply locally.
- Test the round-trip.
- Write data migration if needed. If rows need backfill, add that logic in the same revision — don't split it.
- Mirror to Supabase. The write-through sync layer must know the
shape; update
donna.integrations.supabase_syncif necessary.
Danger Zones¶
- Never edit a landed migration — create a new one.
- Always define
downgrade(); we test recovery. - If the column is
NOT NULL, add it nullable first, backfill, then tighten.