migration

Generate database migrations via Makefile and Alembic autogenerate.

33|5|Updated Feb 12, 2024
One-click install
npx skills add https://github.com/ocbunknown/fastapi-claude-template --skill migration-ocbunknown
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: migration
Source: https://github.com/ocbunknown/fastapi-claude-template/tree/main/.claude/skills/migration
Command: npx skills add https://github.com/ocbunknown/fastapi-claude-template --skill migration-ocbunknown

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Migrations are often handwritten and error-prone. This Skill enforces a standard workflow where migrations are generated via the Makefile and Alembic autogenerate, preventing ad-hoc edits to migration files.

Core Features & Use Cases

  • Enforces generation via the Makefile target and Alembic autogenerate.
  • Provides a clear, repeatable workflow for modifying models, generating migrations, reviewing changes, and applying them.
  • Encourages safe versioning and consistent commits of migration-related changes.

Quick Start

Update your SQLAlchemy models and related types, then generate the migration with NAME describing the change, review the autogenerated file, apply the migration, and commit all changes in one step.

Frequently Asked Questions about migration

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

FAQPage Schema
How do I generate Alembic migrations automatically from SQLAlchemy model changes?

To generate Alembic migrations automatically, update your SQLAlchemy models and run make generate NAME to trigger Alembic autogenerate. Review the autogenerated migration file, apply it with make upgrade, and commit all changes together.

What is the safest workflow for adding new columns and indexes using SQLAlchemy and Alembic?

The safest workflow for schema changes involves updating SQLAlchemy models first, generating a migration via the Makefile and Alembic autogenerate, reviewing the file, and applying it with make upgrade before committing. This prevents error-prone handwritten migrations.

Why should I use Alembic autogenerate instead of writing database migration files manually?

You should use Alembic autogenerate instead of writing migrations manually because handwritten migrations are often error-prone. Enforcing generation through the Makefile standardizes the workflow, preventing ad-hoc edits and ensuring consistent versioning.

Can I use Alembic autogenerate for table alterations and index removal across my models?

Yes, Alembic autogenerate supports schema changes across models including adding or removing columns, indexes, and table alterations. Update the SQLAlchemy models and related types first, then generate the migration with make generate NAME.

What are the limitations of relying on Alembic autogenerate for database schema migrations?

A key limitation is that Alembic autogenerate requires you to review and adjust the autogenerated file before applying it. You must also manually update SQLAlchemy models and related types first, as the tool standardizes generation rather than writing migrations from scratch.

How do I apply a generated Alembic migration and commit the schema changes?

To apply a generated Alembic migration, run make upgrade after reviewing the autogenerated file. Once the database schema is updated successfully, commit all model and migration changes together in a single step for safe versioning.