{"id":48905,"library":"pg-migration-manager","title":"PG Migration Manager","description":"A minimal migration manager for PostgreSQL using the pg driver. Version 1.0.12 is the latest stable release. It reads SQL files from a specified directory and runs them sequentially based on file creation dates, tracking executed migrations in a database table. Unlike heavier tools (e.g., node-pg-migrate), it stays simple with no dependency on query builders or complex configuration. Ships TypeScript types, ESM-only. Ideal for projects that need bare-bones SQL migration management.","status":"active","version":"1.0.12","language":"javascript","source_language":"en","source_url":"https://github.com/AlekseyKowalsky/pg-migration-manager","tags":["javascript","pg","migration","postgresql","typescript"],"install":[{"cmd":"npm install pg-migration-manager","lang":"bash","label":"npm"},{"cmd":"yarn add pg-migration-manager","lang":"bash","label":"yarn"},{"cmd":"pnpm add pg-migration-manager","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: required for database connection pool/client.","package":"pg","optional":false}],"imports":[{"note":"Package is ESM-only; CommonJS require will fail.","wrong":"const MigrationManager = require('pg-migration-manager');","symbol":"default (MigrationManager)","correct":"import MigrationManager from 'pg-migration-manager';"},{"note":"The default export is the class; named import does not exist. Use 'import type' for type-only usage.","wrong":"import { MigrationManager } from 'pg-migration-manager';","symbol":"MigrationManager type","correct":"import type MigrationManager from 'pg-migration-manager';"},{"note":"Configuration type is not exported; extract from constructor parameters.","wrong":"import { Config } from 'pg-migration-manager';","symbol":"Configuration type","correct":"import MigrationManager from 'pg-migration-manager'; type Config = ConstructorParameters<typeof MigrationManager>[1];"}],"quickstart":{"code":"import { Pool } from 'pg';\nimport MigrationManager from 'pg-migration-manager';\n\nconst pool = new Pool({ connectionString: process.env.DATABASE_URL ?? '' });\nconst manager = new MigrationManager(pool, {\n  pathToMigrations: './migrations',\n  migrationTableName: 'migrations'\n});\n\nasync function run() {\n  await manager.runMigrations();\n  console.log('Migrations applied successfully');\n  await pool.end();\n}\nrun().catch(err => { console.error(err); process.exit(1); });\n/*\n  Migration SQL files (e.g., 001_create_users.sql) should be placed in the specified directory.\n  They are executed sequentially based on file creation date.\n*/","lang":"typescript","description":"Connects to PostgreSQL using pg Pool, runs pending SQL migrations from a directory, then closes the pool."},"warnings":[{"fix":"Use ESM imports: import MigrationManager from 'pg-migration-manager'; or wrap in dynamic import().","message":"Package is ESM-only (no CommonJS support). Use dynamic import or set type: 'module' in package.json.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Ensure file creation dates reflect desired order (e.g., touch files in order).","message":"Migrations are run sequentially based on file creation dates, not alphabetical or version order. Changing file creation dates may cause unexpected migration order.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Never rename migration files after they have been applied. Mark changes with new files.","message":"Changing migration file names after they have been run will cause them to be re-run, potentially causing duplicate or conflicting changes.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Write each migration file as a single transactional SQL statement (BEGIN/COMMIT) to ensure atomicity.","message":"Migration runner does not wrap each migration in a transaction by default. If a migration fails, partial changes may remain.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.12':15 'bare':77 'bare-bon':76 'base':33 'bone':78 'builder':61 'complex':63 'configur':64 'creation':36 'databas':43 'date':37 'depend':58 'directori':28 'driver':13 'e.g':48 'esm':69 'esm-on':68 'execut':39 'file':24,35 'heavier':46 'ideal':71 'javascript':82 'latest':18 'manag':3,7,81 'migrat':2,6,40,52,80,84 'minim':5 'need':75 'node':50 'node-pg-migr':49 'pg':1,12,51,83 'postgresql':9,85 'project':73 'queri':60 'read':22 'releas':20 'run':30 'sequenti':32 'ship':65 'simpl':55 'specifi':27 'sql':23,79 'stabl':19 'stay':54 'tabl':44 'tool':47 'track':38 'type':67 'typescript':66,86 'unlik':45 'use':10 'version':14","created_at":"2026-06-07T16:59:03.816053+00:00","updated_at":"2026-06-07T16:59:03.816053+00:00","problems":[{"fix":"Use import MigrationManager from 'pg-migration-manager'; or convert your file to ES module.","cause":"Using CommonJS require() on an ESM-only package.","error":"ERR_REQUIRE_ESM:\n require() of ES Module /path/to/node_modules/pg-migration-manager/index.js from /path/to/app.js not supported.\n Instead change the require of index.js in /path/to/app.js to a dynamic import() which is available in all CommonJS modules."},{"fix":"Use import MigrationManager from 'pg-migration-manager'; without destructuring.","cause":"Importing the package as a named export (e.g., import { MigrationManager }), but it only exports a default.","error":"TypeError: MigrationManager is not a constructor"},{"fix":"Ensure a valid pg Pool or Client is passed, and don't close the pool until after runMigrations resolves.","cause":"Pool is closed before runMigrations completes or no pool/client passed.","error":"Error: Connection terminated unexpectedly"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/AlekseyKowalsky/pg-migration-manager#readme","github":"https://github.com/AlekseyKowalsky/pg-migration-manager","docs":null,"changelog":null,"pypi":null,"npm":"pg-migration-manager","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}