A Node.js CLI tool for managing PostgreSQL schema changes by organizing database objects in SQL files and generating ordered migration scripts with automatic dependency resolution. Version 3.4.0. The tool automatically detects schemas, tables, views, functions, and procedures from source directories, resolves dependencies among them, and compiles an ordered alter.sql script. It can drop existing objects before recreating them, ensuring the target database matches definitions. Supports custom directory structures and multiple source directories. CLI-focused, designed for deterministic migrations with a binary search fallback for error isolation. Differentiators: automatic dependency ordering, object drop detection, and customizable config via altergen.json.
npm install pg-altergenNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows the typical workflow: install, create SQL directory structure, configure altergen.json, generate migration script, then migrate.
Run `pg_dump -h host -U user -d dbname > backup.sql` before using migrate command.
Rename files to match the expected pattern. See documentation for valid prefixes.
Use `pg-altergen generate` instead of `pg-altergen --generate`.
Manually order files within subdirectories if automated resolution fails. Use '--dry-run' to review order.
Rename `config.json` to `altergen.json` and adjust structure. See migration guide.
Run `npm install -g pg-altergen` or `npm install --save-dev pg-altergen`.
Ensure the source_dir exists and contains numbered subdirectories (e.g., 01_schemas) with SQL files matching naming conventions.
Review the generated alter.sql file and fix the problematic SQL statement. Use --dry-run to check for errors before actual migration.
No dependency data recorded yet.