| name | new-migration |
| description | Scaffold a new PostgreSQL migration pair (up + down) with sequential numbering |
| disable-model-invocation | true |
New Migration
Create a new PostgreSQL migration file pair following project conventions.
Usage
/new-migration <description>
Example: /new-migration add_user_preferences
Steps
-
Find the current highest migration number in internal/migrations/sql/:
ls internal/migrations/sql/*.up.sql | sort -t_ -k1 -n | tail -1
-
Calculate the next sequential number (current max + 1).
-
Convert the description argument to lowercase snake_case.
-
Create two files:
internal/migrations/sql/{N}_{description}.up.sql
internal/migrations/sql/{N}_{description}.down.sql
-
Populate the UP migration with a commented template:
-
Populate the DOWN migration with a commented template:
-
Report the created files and remind:
- Use uppercase SQL keywords (ALTER, CREATE, DROP, TABLE, etc.)
- Table/column names use PascalCase (e.g.,
MCPServerLog, project_id)
- DOWN migration must fully reverse the UP migration
- Run
mise run migrate to apply, mise run purge to roll back
- Run
hack/validate-migrations.sh to verify pairing and sequencing
Conventions
- Sequential numbering starting from 0, no gaps
- Each migration must have both
.up.sql and .down.sql
- One logical change per migration
- Foreign keys:
REFERENCES TableName(column_name)
- Index naming:
idx_{table}_{column} or fk_{table}_{column}