alembic-migration

Generates and validates Alembic migrations for PostgreSQL schema changes with SQLAlchemy models.

49|11|Updated Jul 31, 2026
One-click install
npx skills add https://github.com/vstorm-co/agenticos --skill alembic-migration-vstorm-co
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: alembic-migration
Source: https://github.com/vstorm-co/agenticos/tree/main/.claude/skills/alembic-migration
Command: npx skills add https://github.com/vstorm-co/agenticos --skill alembic-migration-vstorm-co

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Changing a SQLAlchemy model without a matching migration passes the mocked unit suite but breaks on real PostgreSQL, and tightening a validation rule on a JSON-stored field can make existing rows unreadable. This Skill guides safe schema evolution with Alembic so model changes, data backfills, and constraint tightening ship together without breaking production data. ## Core Features & Use Cases - Autogenerate-and-review workflow: Change the model, run alembic revision --autogenerate, then review the draft for chained down_revision, reversible downgrade(), and autogenerate blind spots like enums, JSONB, and server defaults. - Data migrations for narrowed rules: Backfill existing rows in the same revision when a validation rule tightens, so old rows remain readable by Pydantic models. - Multi-tenancy and round-trip testing: Retro-fit organization_id constraints (fill, then constrain, in one revision) and prove migrations with tests/test_migrations.py running the whole chain forwards and back. - Use Case: You add a NOT NULL column to an org-scoped table. The Skill walks you through updating the model, autogenerating the revision, adding the backfill UPDATE before the alter_column(nullable=False), and verifying with a downgrade/upgrade round-trip. ## Quick Start Ask the agent to add a new column to a SQLAlchemy model and generate the corresponding Alembic migration with a round-trip test.

Frequently Asked Questions about alembic-migration

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

FAQPage Schema
How do I create an Alembic migration after changing a SQLAlchemy model?▼

Edit the model with Mapped and mapped_column, import it in the models __init__.py, then run alembic revision --autogenerate. Always review the draft: check down_revision chains onto the current head and that downgrade() actually reverses the upgrade.

How do I tighten a validation rule on a JSONB column without breaking existing rows?▼

Ship a data migration in the same revision that backfills existing rows to satisfy the narrower rule. A narrower Pydantic rule makes old rows fail validation, which can take down listing endpoints with 500 errors.

Why does Alembic autogenerate show hundreds of lines of drift?▼

Noisy autogenerate means something was added to a migration by hand and never declared on the model, such as composite indexes or CHECK constraints. Fix the model to match rather than accepting the noise, since real changes hide in it.

Can I edit an Alembic migration that is already applied?▼

Never edit a migration already applied in a shared environment; add a new one instead. Also cite revisions by full file name, since numbering restarted at the 0001_baseline squash and old numbers now resolve to different migrations.

How do I test that an Alembic downgrade actually works?▼

Run alembic upgrade head, then downgrade -1, then upgrade head again, followed by pytest tests/test_migrations.py. That test module runs the whole chain forwards and back against a self-created database, so it is safe alongside a populated dev database.

Why does alembic not manage the rag_ vector store tables?▼

The vector store creates rag_<collection> tables per collection at runtime, so env.py filters them out of autogenerate comparison via include_name. Do not declare them as models, or Alembic would try to drop tenant collections.