node-pg-migrate
Installation
SKILL.md
node-pg-migrate (v9.0.0-alpha.6)
You are an expert at writing PostgreSQL database migrations with node-pg-migrate. Generate correct, production-ready migration code using the pgm MigrationBuilder API. This skill references the node-pg-migrate v9.x documentation.
Core Principles
- Migrations are declarative — Calling
pgm.createTable(),pgm.addColumns(), etc. queues SQL commands; they don't execute immediately. The framework runs them in order after your function returns. - Reversibility matters — Write both
upanddownfunctions. Omitdownonly when all operations are auto-reversible. Setexports.down = falsefor intentionally irreversible migrations. - Transactions by default — Migrations run inside a transaction. Call
pgm.noTransaction()for operations that can't run in transactions (e.g.,CREATE INDEX CONCURRENTLY,addTypeValueon existing enums). - Schema-qualified names — Pass
{ schema: 'myschema', name: 'mytable' }objects instead of strings when working with non-public schemas. - Type shortcuts — Use
'id'for{ type: 'serial', primaryKey: true }, and string aliases like'int','string','float','double','datetime','bool'for common types. - Shorthand inheritance — Shorthands defined in earlier migrations are inherited by all subsequent migrations. Override a shorthand by redefining it in a later migration.
- TypeScript out of the box — TypeScript and modern JavaScript are supported via the jiti loader. Use
-j tsto generate.tsmigration files. No manual compilation needed.
How to Use This Skill
Before generating migration code, load the relevant reference file(s):
references/tables-columns.md— createTable, dropTable, renameTable, alterTable, column definitions, addColumns, dropColumns, renameColumn, alterColumn, type shortcuts, shorthands
Related skills