pg-toolbox is a CLI tool for PostgreSQL database migrations, rollbacks, seeding, and truncation, designed to be used alongside the slonik SQL client. Version 1.1.34 is marked as unstable and not recommended for production—the author advises waiting for v1.2+. Unlike Knex.js or ORMs, this package promotes writing pure SQL to strengthen SQL skills. It has zero production dependencies, using dotenv and slonik only as dev dependencies. Both CJS and ESM module formats are supported, but the API is subject to breaking changes until v1.2. Migrations are ordered alphabetically, and files must export an async function returning an object with migrate/rollback/seed/truncate keys containing slonik SQL tagged templates.
npm install pg-toolboxNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
This shows installation, environment setup, creating a migration file with the expected export format, and running the migration via CLI.
Wait for v1.2.0 release or pin to stable once available. Avoid relying on the current API contract.
Ensure every toolbox file exports an async function returning { migrate: sql`...`, rollback: sql`...`, seed?: ..., truncate?: ... }.Monitor release notes; use Node.js 20+ and --env-file as an alternative, or manually load environment variables.
Use zero-padded numeric prefixes or ISO 8601 timestamps (e.g., '20250101') to guarantee correct ordering.
Ensure pg-toolbox is installed: `npm install pg-toolbox --save-dev`. If running in production, consider moving to dependencies or using a production-compatible fork.
Use the sql tagged template: `sql`CREATE TABLE ...`, not `sql('...')`.Check PGMIGRATIONS path in .env: it should be relative to project root. Ensure the directory exists and contains .js migration files.