Writing Migrations

Create reversible Alembic migrations with explicit upgrade and downgrade paths.

1|2|Updated Feb 5, 2026
One-click install
npx skills add https://github.com/7a336e6e/skills --skill writing-migrations-7a336e6e
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Writing Migrations
Source: https://github.com/7a336e6e/skills/tree/main/database/writing-migrations
Command: npx skills add https://github.com/7a336e6e/skills --skill writing-migrations-7a336e6e

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill automates the creation and management of database schema changes using Alembic, ensuring that all modifications are reversible and tracked.

Core Features & Use Cases

  • Automated Migration Generation: Generates initial migration scripts based on schema differences.
  • Safe Schema Evolution: Provides clear upgrade and downgrade functions for every change.
  • Data Migration Separation: Guides users to keep schema and data modifications distinct.
  • Use Case: When adding a new email column to the users table, this Skill helps generate the necessary Alembic script to add the column, populate it with existing data if needed, and ensure it can be safely removed.

Quick Start

Use the writing migrations skill to generate a new Alembic migration script for adding a 'completed_at' timestamp column to the 'tasks' table.

Frequently Asked Questions about Writing Migrations

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

FAQPage Schema
How do I create reversible Alembic database migrations for schema changes?

Reversible Alembic database migrations are created by generating scripts with explicit upgrade and downgrade paths for adding, modifying, or removing tables, columns, and indexes. This ensures safe schema evolution by allowing forward and backward execution.

How do I handle data migrations separately from schema changes in Python?

Data migrations in Python should be kept distinct from schema modifications to ensure safe database evolution. You generate separate Alembic scripts to populate existing data, such as filling a new column, after applying the structural schema changes.

What is the best way to add a new column to a SQL table and still support a downgrade?

The best way to add a new column to a SQL table while supporting a downgrade is to generate an Alembic migration script. This script defines the upgrade function to add the column and the downgrade function to safely remove it.

Can I test forward and backward execution of database schema migrations?

Yes, you can test forward and backward execution of database schema migrations. The process emphasizes testing both the upgrade and downgrade paths in your Alembic scripts to verify that schema changes can be safely applied and reversed.

Does this approach support modifying indexes and constraints in an existing database schema?

Yes, this approach supports modifying indexes and constraints in an existing database schema. Alembic migration scripts can be generated to handle adding, modifying, or removing these database objects alongside standard table and column alterations.

Why do I need to separate data migrations from schema modifications?

You need to separate data migrations from schema modifications to ensure safe database schema evolution. Keeping them distinct prevents data loss during reversible upgrades and downgrades, allowing structural changes and data population to be managed independently.