pgterra (v0.2.19) is a declarative PostgreSQL schema management tool that generates SQL migration statements by comparing a target schema.sql file against the current state of a PostgreSQL database. Unlike imperative migration tools (e.g., knex, node-pg-migrate), users define the desired schema in a single SQL file and Terra computes the ALTER TABLE, CREATE INDEX, etc. statements needed to reach that state. Written in TypeScript with ESM-only distribution, it supports tables, columns, functions, triggers, sequences, constraints, indexes, enums, views, and procedures. Released under an MIT license with low release cadence, it is primarily a CLI tool (pgterra plan / apply) but can also be used programmatically. Requires Node >=18 and TypeScript ^5.8.3 as a peer dependency.
npm install pgterraNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates programmatic usage: create a Terra instance, preview changes with plan(), then apply via apply().
Use `new Terra(options)` instead of `Terra(options)`.
Use named import: `import { Terra } from 'pgterra'`.Use `import` syntax or dynamic import() in CommonJS projects.
Combine all schema definitions into a single .sql file.
Prefer DATABASE_URL or ensure all DB_* variables are set.
Convert to ES module (type: 'module' in package.json) or use dynamic import: `const { Terra } = await import('pgterra')`.Use `const terra = new Terra(options)`.
Set DATABASE_URL or ensure DB_HOST, DB_PORT, DB_NAME, DB_USER, DB_PASSWORD are all set.