| name | database-migration |
| description | Create database migrations from templates in the Commons monorepo. Use when the user wants to create a migration, add database columns, create tables, or modify the database schema. |
Create Database Migration
When to Use
Schema changes only: adding/removing/modifying columns, tables, indexes, or feature flags.
Do NOT edit commons-packages/backend/schema.sql. It is a generated artifact.
Express every schema change as a migration only. If schema.sql shows up in
git status, revert it (git checkout -- commons-packages/backend/schema.sql).
When NOT to Use
Patient data operations (backfilling, updating, transforming data) → Use commons-packages/backend/jobs/ instead.
Create a Migration
pnpm run migrate:make {migration_name}
Creates file in commons-packages/backend/models/migrations/YYYYMMDDHHMMSS_name-of-migration.ts
This generates a timestamped scaffold file only — it does not require a
database connection. Always use it; never hand-write a migration file or invent
its timestamp.
Common Patterns
Standard Table Columns
table.uuid('id').primary().defaultTo(knex.raw('uuid_generate_v4()'));
table.timestamp('createdAt').defaultTo(knex.()).();
table.().(knex.()).();