Create, review, test, and rollback Alembic database migrations for OPRE OPS. Use this skill whenever the user mentions database migrations, alembic, schema changes, adding/modifying columns or tables, model changes that need migration, or "migrate the database". Also use when a model change has been made and the user needs to generate the corresponding migration.
90
88%
Does it follow best practices?
Impact
96%
0.98xAverage score across 3 eval scenarios
Passed
No known issues
You manage Alembic database migrations for the OPRE OPS project. Migrations must be run from the backend/ directory because that's where alembic.ini lives and where models is importable.
Interpret $ARGUMENTS to decide the action:
$ARGUMENTS starts with createGenerate a new migration from model changes.
Step 1: Verify the working directory and database
cd backend
# Check that the database is running
docker compose ps db --format json 2>/dev/null | jq -r '.Name + " " + .State' || echo "DB service not found — is Docker running?"
# Check current migration state
alembic currentIf the database isn't running, tell the user:
docker compose up db -dStep 2: Check for model changes
Look at what's changed to understand what the migration should contain:
# What model files have changed on this branch?
git diff main...HEAD --name-only -- models/
# Or if working off unstaged changes:
git diff --name-only -- models/Read the changed model files to understand the schema changes.
Step 3: Generate the migration
Extract the message from $ARGUMENTS (everything after "create"):
cd backend
alembic revision --autogenerate -m "your migration message"Migration files follow the naming pattern: YYYY_MM_DD_HHMM-<revision>_<slug>.py and are created in backend/alembic/versions/.
Step 4: Review the generated migration (critical!)
Auto-generated migrations can miss things or generate incorrect operations. Read the new file and check for:
op.alter_column() instead.downgrade() reverses the upgrade() correctly.Present a summary to the user: "Here's what the migration does: [list of operations]. Does this look right?"
Step 5: Test the migration
cd backend
# Apply the migration
alembic upgrade head
# Verify it applied
alembic current
# Test the downgrade
alembic downgrade -1
# Re-apply to leave DB in upgraded state
alembic upgrade headReport results: whether upgrade and downgrade both succeeded, and any errors encountered.
$ARGUMENTS is review or review <filename>Review an existing migration file for correctness.
If a specific filename is provided, read that file. Otherwise, review the most recent migration:
ls -t backend/alembic/versions/*.py | head -1Check for the same issues listed in Step 4 above. Also check:
Revises: points to the expected parent)if not guards for index creation)$ARGUMENTS is upgrade or upgrade <target>Apply migrations:
cd backend
# Upgrade to head (default)
alembic upgrade head
# Or upgrade to a specific revision
alembic upgrade <target>
# Verify
alembic current$ARGUMENTS is downgrade or downgrade <target>Roll back migrations:
cd backend
# Roll back one migration (default)
alembic downgrade -1
# Or downgrade to a specific revision
alembic downgrade <target>
# Verify
alembic current$ARGUMENTS is statusShow the current migration state:
cd backend
# Current revision applied to the database
alembic current
# Check if there are unapplied migrations
alembic check 2>&1 || true
# Show the head revision
alembic headsReport whether the database is up to date or has pending migrations.
$ARGUMENTS is historyShow recent migration history:
cd backend
# Show last 10 migrations
alembic history -r -10:current --verbose$ARGUMENTS is empty or unrecognizedShow help:
Database Migration Skill - Available Commands:
/db-migrations create <message> Generate a new migration from model changes
/db-migrations review Review the most recent migration for correctness
/db-migrations review <file> Review a specific migration file
/db-migrations upgrade Apply all pending migrations (alembic upgrade head)
/db-migrations downgrade Roll back one migration (alembic downgrade -1)
/db-migrations status Show current migration state and pending changes
/db-migrations history Show recent migration history
Prerequisites:
- Docker database must be running: docker compose up db -d
- Run from backend/ directory (handled automatically by this skill)
- 67 existing migrations in backend/alembic/versions/backend/alembic.inibackend/alembic/versions/ (67 migrations)backend/alembic/env.pybackend/models/ (shared across ops_api and data_tools)backend/data_tools/scripts/initial_data.sh, backend/data_tools/scripts/upgrade_schema.shbackend/, not backend/ops_api/ or the project rootop.alter_column() with new_column_name manually.op.execute("ALTER TYPE ... ADD VALUE ...") manually.before_commit/after_flush for history tracking. Migrations that add new models should ensure the corresponding *_history table is also created if the model inherits from BaseModel.e2a9461
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.