Skip to content
Select themeSelect language

Add a database migration

SupaCloud uses sequential, numbered SQL migrations in server/migrations/.

  1. Find the next number — safely. Migration numbers are a shared namespace across parallel developers and worktrees. Before picking a number:

    Terminal window
    git fetch
    ls server/migrations/ # scan the highest number on main

    Also scan any sibling worktrees. Then take the next free number.

  2. Add the file as NNN_short_description.sql in server/migrations/.

  3. Keep closed CHECK vocabularies executable. If a migration renames a stored value to one the old CHECK (... IN (...)) does not permit, use this exact sequence: DROP CHECK → UPDATE old rows → ADD CHECK. A deletion or a rewrite to a value already permitted by the old CHECK may happen before the narrowing CHECK. The committed guard catches the unsafe rename order:

    Terminal window
    python3 scripts/check-migration-check-order.py --self-test
    python3 scripts/check-migration-check-order.py

    Add a seeded upgrade test whenever rows can carry the old value; an empty database cannot expose this class of failure.

  4. Verify it applies and the server still type-checks:

    Terminal window
    cd server && cargo check