Logotipo de Migration

Migration

Comunidad
ewtryocb
migration

Use when the user asks to create a database migration, change a SQLAlchemy model, add a column, add an index, or otherwise modify the schema. Enforces the rule that migrations are generated via `make generate NAME="..."` (the project's Makefile target that runs Alembic autogenerate) — never hand-written — and never edit existing migration files in migrations/versions/.

Descripción general

Editorewtryocb
Repositoriofastapi-claude-template
Nombre de la habilidadmigration
Estrellas
33
Forks
5
Archivos incluidos
Solo instrucciones
LicenciaMIT
Enlaces
  • Instrucciones en Markdown

    Un archivo SKILL.md que el modelo carga cuando lo necesita, de modo que solo consume tokens cuando una petición es realmente relevante.

  • Funciona con cualquier LLM

    Las habilidades de IA están en Markdown, no en código específico de un proveedor, por lo que funcionan con GPT, Claude, Gemini, Grok o un modelo local.

  • Todo en las instrucciones

    Todo lo que necesita el modelo está en las instrucciones: no hay archivos adicionales que sincronizar.

  • Código abierto

    Publicada por ewtryocb en GitHub. Revisa el contenido original antes de instalarla.

Instalación

Instala la habilidad de IA Migration en TypingMind para usarla con cualquier LLM, o añádela a otro agente que lea SKILL.md.

1

Instalar en TypingMind

TypingMind instala una habilidad directamente desde su carpeta de GitHub: lee SKILL.md, empaqueta los archivos de recursos y guarda el resultado localmente.

  1. Abre la aplicación y ve a Plugins → Habilidades.
  2. Elige «Instalar desde GitHub».
  3. Pega la URL de la carpeta de la habilidad que se muestra a continuación y confirma.
    https://github.com/ewtryocb/fastapi-claude-template/tree/master/.claude/skills/migration
  4. Activa la habilidad en cada chat en el que quieras tenerla disponible.
Plugins → Habilidades → Añadir habilidad → Desde URL de GitHub; después, pega la URL de la carpeta y pulsa Continuar.
2

Instalar en otro agente

Cualquier agente que lea el formato Agent Skills puede usar esta habilidad: copia la carpeta en el directorio de habilidades de ese agente.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/ewtryocb/fastapi-claude-template.git /tmp/fastapi-claude-template
mkdir -p .claude/skills
cp -r /tmp/fastapi-claude-template/.claude/skills/migration .claude/skills/migration
Reinicia Claude Code después de copiarla para que detecte la nueva habilidad.

Úsala en TypingMind

Activa Migration en cualquier chat de TypingMind y el modelo se encargará del resto. Su nombre y descripción se incluyen en el prompt del sistema y, en cuanto una petición es relevante, el modelo carga las instrucciones completas por sí solo. No tienes que invocarla manualmente y no consume tokens hasta que se utiliza.

El modelo carga Migration automáticamente en cuanto una petición es relevante para esa habilidad.

Funciona con cualquier modelo de IA

Las habilidades de IA son instrucciones en Markdown, no código específico de un proveedor, por lo que Migration no está vinculada al modelo para el que se creó. Instálala una sola vez en TypingMind y úsala con GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama o un modelo local que ejecutes tú, todo con tus propias claves API.

  • Se carga solo cuando se necesita

    El prompt del sistema solo incluye el nombre y la descripción. Las instrucciones se cargan con la primera petición relevante, por lo que una habilidad que no se usa no supone ningún coste.

  • Cambia de modelo durante el chat

    Como la habilidad contiene instrucciones y no código, cambiar de modelo no impide que funcione: el nuevo modelo lee el mismo archivo SKILL.md.

Instrucciones de la habilidad

Este es el contenido de SKILL.md que carga el modelo. Léelo antes de instalar la habilidad: contiene instrucciones que tu modelo seguirá.

Creating database migrations

Migrations in this project are generated via the Makefile, which wraps Alembic's autogenerate. You never write migration files by hand, and you never edit an existing migration file.

The three Makefile targets

makefile
upgrade:    alembic upgrade head                # apply all pending migrations
downgrade:  alembic downgrade -1                # roll back the latest migration
generate:   alembic revision --autogenerate -m "$(NAME)"   # create a new migration

Run them from the repo root. The generate target requires a NAME variable — Alembic uses it as the migration message (and as part of the filename slug).

The standard workflow

When the user asks for a schema change, follow this exact order:

  1. Edit the SQLAlchemy model under src/database/psql/models/<entity>.py. Add/remove columns, indices, constraints, relationships — whatever the request needs.

  2. Update companion types under src/database/psql/types/<entity>.py:

    • If a new writable column: add it to Create<Entity>Type (required) and/or Update<Entity>Type (optional, total=False).
    • If a new relationship: add its name to <Entity>Loads = Literal[...].
  3. Generate the migration via the Makefile — do not call alembic directly:

    bash
    make generate NAME="add_is_verified_to_user"

    Alembic autogenerate will diff the model metadata against the current DB schema and write a new file to migrations/versions/NN_<hash>_add_is_verified_to_user.py. The NN_ numeric prefix is added by the project's naming convention — Alembic appends the hash + slug.

  4. Inspect the generated file. Autogenerate is imperfect — it often misses:

    • Column type changes (e.g. String(32) → String(64) may require manual alter_column with existing_type)
    • Index renames
    • Enum value additions (Postgres ALTER TYPE ... ADD VALUE)
    • server_default changes
    • Data migrations (filling a new NOT NULL column for existing rows)

    Open the generated file and verify the upgrade() and downgrade() functions match your intent. If anything is missing or wrong, edit the generated file now — it is fresh, uncommitted, not yet applied. Once a migration is applied to dev/staging/prod, it becomes immutable.

  5. Apply it locally:

    bash
    make upgrade
  6. Test it — run the relevant integration tests under tests/integration/ (they use testcontainers to spin up a real Postgres and apply migrations).

  7. Commit the model change, the types change, and the migration file in one commit. They must never be committed separately — a repo where models.py and migrations/versions/ disagree is broken.

Naming convention

Pass a snake_case, imperative-ish, description to NAME:

GoodBad
add_is_verified_to_user"added verified"
create_widget_table"widget"
rename_user_email_to_login"rename"
drop_legacy_permissions_column"cleanup"
add_gin_index_on_user_login"index"

Keep it under ~50 chars. The slug ends up in the filename and in git log, so it should stand alone.

What NOT to do

  • ❌ Do not write a new migration file by hand. Always use make generate NAME="...". Autogenerate is the starting point even if you'll have to edit it.
  • ❌ Do not call alembic revision --autogenerate directly. Use the Makefile target so the invocation is consistent across environments.
  • ❌ Do not edit an existing migration file in migrations/versions/ (01_...py, 02_...py, etc.). These are immutable history. A PreToolUse hook (.claude/hooks/guard_paths.py) blocks any edit to these files — if you see the block, you're doing something wrong. If you need to fix a bug in a migration that was already applied, write a new migration that corrects it; don't rewrite history.
  • ❌ Do not edit migrations/env.py casually — it's the Alembic bootstrap that the hook also protects. If you genuinely need to change it (e.g., to register a new metadata target), do it outside Claude's edit flow.
  • ❌ Do not apply a migration without generating + inspecting the file first. Autogenerate output is your audit trail — if you skip it, you lose traceability.
  • ❌ Do not autogenerate a migration against a schema that's out of sync with head. Run make upgrade first to bring the DB current, otherwise the diff will include changes from earlier, already-shipped migrations.

When autogenerate is not enough

Autogenerate is blind to:

  • Data migrations — if a new NOT NULL column needs a value for existing rows, you must write an op.execute("UPDATE ...") before the op.alter_column(..., nullable=False).
  • Enum mutations — Postgres enums need op.execute("ALTER TYPE <name> ADD VALUE '<val>'"); autogenerate doesn't emit this.
  • Complex index types — GIN, GiST, partial indexes, expression indexes may need hand-written op.create_index.
  • Check constraints with SQL expressions — autogenerate detects the constraint name but may miss the expression text.

For these cases: generate the migration normally, then edit the generated file (still allowed before commit) to add the missing op.execute(...) or op.create_index(...) calls, and update the downgrade() to reverse them.

Rollback discipline

Every upgrade() must have a real downgrade(). Never leave pass in downgrade() unless the operation is genuinely irreversible (and even then, prefer raising NotImplementedError to make the intent explicit).

Checklist (run this before handing back to the user)

  • Edited the model in src/database/psql/models/<entity>.py
  • Updated Create<Entity>Type / Update<Entity>Type / <Entity>Loads in src/database/psql/types/<entity>.py if applicable
  • Ran make generate NAME="<snake_case_desc>"
  • Opened the generated file and verified upgrade() / downgrade() match intent
  • Added any missing data migrations, enum ops, or custom index calls
  • Ran make upgrade locally
  • Ran the relevant integration tests
  • Staged model + types + migration together for one commit

Preguntas frecuentes

¿Qué hace la habilidad de IA Migration?

Use when the user asks to create a database migration, change a SQLAlchemy model, add a column, add an index, or otherwise modify the schema. Enforces the rule that migrations are generated via `make generate NAME="..."` (the project's Makefile target that runs Alembic autogenerate) — never hand-written — and never edit existing migration files in migrations/versions/.

¿Por qué usar Migration en TypingMind?

Porque la instalas una vez y la usas con cualquier modelo. Migration está escrita en Markdown, no en código específico de un proveedor, por lo que la misma habilidad funciona con GPT-5, Claude, Gemini, Grok o un modelo local, y puedes cambiar de modelo en mitad del chat sin que deje de funcionar. TypingMind utiliza tus propias claves API, de modo que pagas directamente a los proveedores en lugar de pagar una suscripción por puesto, y tus habilidades y chats permanecen en tu propio almacenamiento.

¿Cómo instalo Migration en TypingMind?

Abre Plugins → Habilidades → Instalar desde GitHub en TypingMind y pega https://github.com/ewtryocb/fastapi-claude-template/tree/master/.claude/skills/migration. TypingMind lee su archivo SKILL.md y la instala como una habilidad que puedes activar en cada chat.

¿Qué modelos de IA pueden usar Migration?

Cualquier modelo que conectes en TypingMind. Las habilidades de IA son instrucciones en Markdown, no código específico de un proveedor, por lo que GPT, Claude, Gemini, Grok y los modelos locales pueden cargar esta habilidad cuando una solicitud se corresponda con ella.

¿Con cuántos modelos de IA puedo usar Migration?

Con tantos como quieras. Siempre que un modelo admita habilidades, puedes usar Migration con él: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama y muchos más, todos en TypingMind con tus propias claves API.

¿Es gratuita la habilidad de IA Migration?

Sí. ewtryocb la ha publicado en GitHub bajo la licencia MIT. Solo pagas a tu proveedor de IA por los tokens que utilizas.

¿Qué son las habilidades de IA?

Una habilidad de IA es un conjunto de instrucciones reutilizables que enseña a un modelo de IA a realizar una tarea concreta. Sigue el formato abierto Agent Skills: un archivo SKILL.md con un nombre y una descripción, además de los scripts, plantillas o archivos de referencia que pueda necesitar el modelo. El modelo solo lee las instrucciones cuando tu solicitud se corresponde con la habilidad, por lo que una habilidad instalada no supone ningún coste hasta que se utiliza.

¿En qué se diferencian las habilidades de IA de los plugins o los servidores MCP?

Un plugin o un servidor MCP proporciona al modelo nuevas herramientas que puede invocar: código que se ejecuta en algún lugar y devuelve un resultado. En cambio, una habilidad de IA aporta conocimientos y procedimientos al modelo: cómo abordar una tarea, qué pasos seguir y qué se considera un buen resultado. Las habilidades son instrucciones en Markdown, por lo que no necesitan servidor, clave API ni entorno de ejecución, y funcionan con cualquier modelo.

Ver todos

Crea ya tu propio espacio de trabajo IA

Suscríbete a nuestro boletín para recibir avisos sobre nuevas funciones y próximos sorteos 👇