Back to Skills

database-migration

Database schema change and Alembic migration expertise. Use when modifying database models, creating migrations, handling rollbacks, or troubleshooting migration issues. Ensures data integrity and safe schema evolution.

2starsUpdated 3/19/2026

Security Assessment

Low Risk(70/100)

Detected risks:

Destructive Operations([SKILL.md] rm -rf)
Security Score70/100

About database-migration

The database-migration skill provides expert guidance for safely managing and evolving database schemas using Alembic in combination with SQLAlchemy models. It ensures that all changes to database models are accompanied by the appropriate migration scripts, maintaining data integrity and preventing potential disruptions. This skill addresses common challenges encountered during schema evolution, such as modifying existing tables, adding or removing columns, creating foreign key relationships, and handling rollback scenarios, all while preserving a stable database state.

Key features include step-by-step guidance for modifying models, generating migrations, reviewing and testing migrations, and safely committing changes. The skill outlines patterns for common operations, including adding nullable or non-nullable columns, creating indexes, and establishing foreign key constraints. It emphasizes safe practices, such as backfilling data when adding non-nullable columns and verifying migrations through upgrade and downgrade operations, ensuring that developers can confidently apply schema changes without risking data loss or corruption.

This skill is particularly useful for backend developers, database administrators, and DevOps engineers who work with Python applications using SQLAlchemy and Alembic. It supports tasks ranging from routine schema updates to complex migrations, including troubleshooting migration errors. Users seeking structured guidance for maintaining consistent database evolution, ensuring smooth rollbacks, and enforcing best practices in version-controlled migrations will benefit most from this skill.

FAQ

When should I use the database-migration skill?

Use this skill whenever you need to modify database models, add or remove columns, create foreign keys, rename tables or columns, or troubleshoot migration issues. It ensures that all changes are properly reflected in Alembic migrations.

Which frameworks or libraries are compatible with this skill?

This skill is designed to work with Python applications using SQLAlchemy for ORM models and Alembic for database migrations.

Can I apply migrations directly without reviewing them?

No. It is recommended to review autogenerated migration scripts to ensure correctness before applying them. This prevents potential data issues or unexpected schema changes.

How can I safely add a non-nullable column?

First, add the column as nullable, then backfill existing rows with default values, and finally alter the column to be non-nullable. This ensures existing data remains consistent.

What are the limitations of this skill?

This skill assumes the use of SQLAlchemy models and Alembic for migrations. It does not cover other ORMs or database migration tools, and it relies on following recommended workflows to maintain safety.

Install database-migration

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill