database-migrations

Automate Alembic database migrations with reversible upgrade and downgrade scripts.

2|Updated Nov 13, 2025
One-click install
npx skills add https://github.com/ricardoroche/ricardos-claude-code --skill database-migrations
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: database-migrations
Source: https://github.com/ricardoroche/ricardos-claude-code/tree/main/.claude/skills/database-migrations
Command: npx skills add https://github.com/ricardoroche/ricardos-claude-code --skill database-migrations

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires alembic, sqlalchemy, pytest.

What problem does it solve?

This Skill provides best practices for managing database schema changes using Alembic, addressing issues like irreversible migrations, data loss during rollbacks, and inconsistent schema evolution. It ensures safe, reproducible, and testable database updates, minimizing downtime and data integrity risks.

Core Features & Use Cases

  • Alembic Setup & Usage: Guides on configuring alembic/env.py and creating migrations with alembic revision --autogenerate.
  • Safe Schema Changes: Provides patterns for safely adding columns (nullable first), modifying column types, and handling foreign key changes.
  • Data Migrations: Explains how to perform data transformations within migrations, including multi-phase approaches for complex data changes.
  • Migration Testing: Offers patterns for writing pytest tests to verify migrations can upgrade and downgrade, and preserve data integrity.
  • Use Case: A backend team needs to add a new phone column to the users table and migrate existing status values. This skill guides them to add the column as nullable first, then update existing data, and finally make it non-nullable, ensuring no data loss and a smooth deployment.

Quick Start

Create a new Alembic migration to add a phone column to the users table, ensuring it's added as nullable first.

Frequently Asked Questions about database-migrations

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely add a column to a database table without data loss?

Add the column as nullable first using Alembic migrations, then update existing data, and finally make it non-nullable. This phased approach prevents data loss and allows rollback at each stage during deployment across environments.

What's the best way to test database migrations before deploying to production?

Write pytest tests that verify migrations upgrade and downgrade successfully while preserving data integrity. Test both forward and reverse paths to catch issues before production deployment.

How do I perform data transformations during a database migration?

Use Alembic migration scripts to embed data transformation logic alongside schema changes. For complex changes, apply multi-phase migrations that separate schema alterations from data updates for safety and clarity.

Can I roll back schema changes if a migration fails in production?

Yes. Alembic supports reversible upgrade and downgrade scripts, enabling you to roll back failed migrations. Write downgrade paths that safely restore the previous schema state and data.

Does Alembic work with SQLAlchemy for managing schema evolution?

Yes. Alembic integrates with SQLAlchemy to detect schema changes automatically using `alembic revision --autogenerate`. It generates migration scripts that track and apply schema evolution across development, staging, and production.

Why do irreversible migrations cause problems in team deployments?

Irreversible migrations prevent rollbacks when issues occur, risking data loss and extended downtime. Alembic migrations enforce reversibility by requiring both upgrade and downgrade paths, enabling safe recovery across all deployment environments.