SQL migration tool for Node.js using plain SQL or JavaScript files, supporting PostgreSQL, MySQL, SQL Server, and SQLite. Version 8.0.0 requires Node >=20 and publishes TypeScript types. Postgrator is ESM-only as of v6, tracks migrations in a schema table, and automatically determines directional migration (up/down). Key differentiators: file-based versioning with .do.sql/.undo.sql convention, optional JS/async migration scripts, and no ORM dependency. Released under MIT license, maintained by Rick Bergfalk.
npm install postgratorNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Creates a Postgrator instance with a PostgreSQL client, runs migrations to version '005' using a migration folder.
Use import (ESM) or migrate to dynamic import(). Set type: 'module' in package.json.
Upgrade Node.js to version 20 or later.
Change 'currentSchema' to 'schemaTable' with format 'schema.table' if needed.
Ensure files match pattern exactly, e.g., 001.do.my-migration.sql.
Use module.exports.generateSql = function() { ... } or export function generateSql() { ... } for ESM.Always provide an undo script for each migration, or ensure you never need to downgrade past a migration without one.
Switch to import statement, or use dynamic import() inside a CommonJS module.
Verify the pattern path relative to process.cwd(). Use absolute paths or __dirname based paths.
Set driver to exactly one of the supported drivers: 'pg', 'mysql', 'mssql', 'sqlite', 'mysql2'.
npm install pg (or mysql2, mssql, better-sqlite3 depending on driver).