Skip to content
Back to skills

Ape Migration

ASecurity

Create or change database tables: change entities, generate the module migration, review up and down, round-trip.

  • 5 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
developmentgoexpressdatabase

Works with

  • mcp

Security analysis

A100/100

Scanned December 3, 2026

npx -y skills add BuffApe/BuffApe --skill ape-migration --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Ape Migration?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Ape Migration
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/buffape-ape-migration/badge)](https://www.skillsdirectory.com/skills/buffape-ape-migration)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: ape-migration
description: "Create or change database tables: change entities, generate the module migration, review up and down, round-trip."
---

# Migrations

A migration is namespaced by its module, its tables are not: it is recorded as `<module>/<name>` (`app_migrations` for a product's, `buffcore_migrations` for BuffCore's), and a product's table keeps a plain name (`posts`, like the reference module's `tasks`). Only an extension prefixes its tables with its key (`payments_customers`). A name BuffCore's tables or another module already use stops the app at start, naming both.

The `ape mcp` tool `db_schema` lists the tables that exist.

1. Change the module's entities.
2. Run `pnpm ape migrate create <module> <name>`. It replays the module's migrations on a throwaway database, diffs the entities, and writes `migrations/NNNN-<name>.ts` covering only the module's own tables.
3. Add the file to `migrations/index.ts`.
4. Review `up` and `down` by hand. Extensions (`create extension if not exists …`), data moves and defaults are yours to add. Migrations stay compatible with the release running before them: expand first, contract later.
   - **A deploy's migrations only add.** When an entity loses a field, the generator writes a `drop column`: take it out of this migration and ship it in a later change, once the release that stops reading the field runs. A renamed field is a new column, filled, and the old one dropped later. A new required column gets a `default`. `pnpm ape migrate check` says what a pending migration would take away; `ape deploy` refuses it when the running release still reads it.
   - An index the generator can't write (a trigram `gin` index, an index on an expression) goes in the migration by hand and is also declared on the entity, `indexes: [{ name, expression }]` with the full `create index …` statement, so the generator shows no drift the next time.
   - `down` drops only what the migration made. It leaves a shared extension such as `pg_trgm` in place, because other tables use it.
5. Round-trip: `pnpm ape migrate`, `pnpm ape migrate down`, `pnpm ape migrate`. CI repeats it.
6. Never edit a migration that has run anywhere but your own machine; write a new one.
7. Renumber your new migration if merge, Catch up or `ape change --check` names a migration with the same number on main. `ape migrate status` reports migrations applied here, not in this code, with recovery guidance.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.