{"id":43566,"library":"pg-node-migrations","title":"pg-node-migrations","description":"A PostgreSQL migration library for Node.js (v0.0.8) based on ThomWright's postgres-migrations, adding support for custom schema and migration table names. Migrations are defined in sequential SQL files (starting at 0_) and run in order with no down migrations. Requires Node >10.17.0 and supports PostgreSQL 9.4+. Ships TypeScript types. Key differentiator vs alternatives: simple file-based ordering, no timestamp reliance, and ability to run in custom schema/table.","status":"active","version":"0.0.8","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/jbelelieu/pg_node_migrations","tags":["javascript","postgres","postgresql","migration","migrations","sql","database","db","typescript"],"install":[{"cmd":"npm install pg-node-migrations","lang":"bash","label":"npm"},{"cmd":"yarn add pg-node-migrations","lang":"bash","label":"yarn"},{"cmd":"pnpm add pg-node-migrations","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for database connection","package":"pg","optional":false}],"imports":[{"note":"Package ships TypeScript types and is ESM-compatible. CommonJS require may work but is not recommended.","wrong":"const { migrate } = require('pg-node-migrations')","symbol":"migrate","correct":"import { migrate } from 'pg-node-migrations'"},{"note":"Used for validation of migration file ordering.","symbol":"loadMigrationFiles","correct":"import { loadMigrationFiles } from 'pg-node-migrations'"},{"note":"TypeScript type import for migration direction enum.","symbol":"MigrationDirection","correct":"import type { MigrationDirection } from 'pg-node-migrations'"}],"quickstart":{"code":"import { migrate } from 'pg-node-migrations';\nimport path from 'path';\n\nasync function runMigrations() {\n  const dbConfig = {\n    database: 'mydb',\n    user: 'postgres',\n    password: process.env.DB_PASSWORD ?? '',\n    host: 'localhost',\n    port: 5432,\n    ensureDatabaseExists: true,\n    defaultDatabase: 'postgres',\n  };\n\n  const optionalConfig = {\n    schemaName: 'mySchema',\n    tableName: 'myMigrations',\n  };\n\n  await migrate(dbConfig, path.join(__dirname, 'migrations'), optionalConfig);\n  console.log('Migrations applied successfully');\n}\n\nrunMigrations().catch(console.error);","lang":"typescript","description":"Shows basic usage of migrate() with custom schema/table, using database config object."},"warnings":[{"fix":"Explicitly set `ensureDatabaseExists: true` if you want the database to be created automatically.","message":"The `ensureDatabaseExists` option defaults to `false` for backwards compatibility but may change to `true` in future versions.","severity":"breaking","affected_versions":">=0.0.1"},{"fix":"Ensure file names follow the pattern: <number>_<description>.sql, starting from 0.","message":"Migrations must start with a number followed by underscore (e.g., 0_create-table.sql) and be sequentially numbered without gaps.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"If using a client, create the database beforehand or use the config object instead.","message":"When passing a pg Client, Pool, or PoolClient to migrate, the database must already exist; ensureDatabaseExists is ignored.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Place only .sql files in the migration directory.","message":"Only SQL files are supported for migrations; other file types will be ignored.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"search_vec":"'0':37 '10.17.0':48 '9.4':52 'abil':69 'ad':19 'altern':59 'base':12,63 'custom':22,73 'databas':81 'db':82 'defin':30 'differenti':57 'file':34,62 'file-bas':61 'javascript':75 'key':56 'librari':8 'migrat':4,7,18,25,28,45,78,79 'name':27 'node':3,47 'node.js':10 'order':41,64 'pg':2 'pg-node-migr':1 'postgr':17,76 'postgres-migr':16 'postgresql':6,51,77 'relianc':67 'requir':46 'run':39,71 'schema':23 'schema/table':74 'sequenti':32 'ship':53 'simpl':60 'sql':33,80 'start':35 'support':20,50 'tabl':26 'thomwright':14 'timestamp':66 'type':55 'typescript':54,83 'v0.0.8':11 'vs':58","created_at":"2026-06-05T17:00:24.764931+00:00","updated_at":"2026-06-05T17:00:24.764931+00:00","problems":[{"fix":"Rename files to ensure sequential order (e.g., 0_, 1_, 2_) with no missing numbers.","cause":"Migration files have gaps in numbering or duplicates.","error":"Error: Migration files must be sequentially numbered"},{"fix":"Remove ensureDatabaseExists from config when using client; the database must already exist.","cause":"Passing a client object with ensureDatabaseExists in config.","error":"Error: ensureDatabaseExists is not a valid option when using a client"},{"fix":"Run `npm install pg` to install the peer dependency.","cause":"pg package is not installed.","error":"Error: Cannot find module 'pg'"}],"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/jbelelieu/pg_node_migrations#readme","github":"ssh://git@github.com/jbelelieu/pg_node_migrations","docs":null,"changelog":null,"pypi":null,"npm":"pg-node-migrations","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-05","next_check":"2026-09-03","install_tag":null}}