Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Ape Migration?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/buffape-ape-migration)
---
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.