Agent skill
create-db-migration
Creates Alembic database migrations safely. Use when schema changes are needed, adding tables, columns, indexes, or modifying database structure.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/data/create-db-migration
SKILL.md
Create Database Migration
Creates Alembic database migrations for schema changes.
Prerequisites
Ensure Docker containers are running:
docker compose ps
If not running, start them:
docker compose up -d
Workflow
1. Create Migration
docker compose exec back uv run alembic revision --autogenerate -m "Description of change"
Good migration descriptions:
- "Add notifications table"
- "Add index on users.email"
- "Add description column to items"
- "Remove deprecated legacy_id column"
2. Review Migration
After creation, review the generated migration file in back/alembic/versions/.
Check for:
- Correct
upgrade()anddowngrade()operations - No data loss in
downgrade() - Proper index creation
- Foreign key constraints
3. Apply Migration Locally
Migrations run automatically on container restart, or manually:
docker compose exec back uv run alembic upgrade head
4. Verify
docker compose exec back uv run alembic current
Common Migration Patterns
Add Column
def upgrade():
op.add_column('table_name', sa.Column('column_name', sa.String(), nullable=True))
def downgrade():
op.drop_column('table_name', 'column_name')
Add Index
def upgrade():
op.create_index('ix_table_column', 'table_name', ['column_name'])
def downgrade():
op.drop_index('ix_table_column', table_name='table_name')
Add Table
def upgrade():
op.create_table(
'table_name',
sa.Column('id', sa.UUID(), primary_key=True),
sa.Column('created_at', sa.DateTime(), nullable=False),
)
def downgrade():
op.drop_table('table_name')
Warnings
- Destructive operations: Be careful with
DROP TABLE,DROP COLUMN - Data migrations: Consider data preservation in downgrade
- Production: Migrations run via Lambda, triggered by CI/CD after deployment
Production Migration
In deployed environments:
- Migrations run via dedicated Migration Lambda
- Triggered automatically by CI/CD after deployment
- Manual trigger:
aws lambda invoke --function-name template-saas-api-migrate-lambda-{stage} /dev/null
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?