Gathering detailed insights and metrics for node-pg-migrate
Gathering detailed insights and metrics for node-pg-migrate
Gathering detailed insights and metrics for node-pg-migrate
Gathering detailed insights and metrics for node-pg-migrate
node-pg-migrate-exp
PostgreSQL database migration management tool for node.js
@liveaxle/node-pg-migrate
Synchronous (async/await) migration assistant for PostgreSQL
@contember/database-migrations
node-pg-migrate wrapper
@osdiab/node-pg-migrate
Postgresql database migration management tool for node.js
Node.js database migration management for PostgreSQL
npm install node-pg-migrate
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (88.42%)
JavaScript (11.58%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
1,380 Stars
1,349 Commits
183 Forks
14 Watchers
11 Branches
81 Contributors
Updated on Jul 04, 2025
Latest Version
8.0.3
Package Id
node-pg-migrate@8.0.3
Unpacked Size
521.12 kB
Size
104.55 kB
File Count
286
NPM Version
10.9.2
Node Version
22.16.0
Published on
Jun 18, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
37
Node.js database migration management built exclusively for postgres. (But can also be used for other DBs conforming to SQL standard - e.g. CockroachDB.)
Started by Theo Ephraim, then handed over to Salsita Software and now maintained by @Shinigami92.
If you don't already have the pg
library installed, you will need to add pg as either a direct or dev dependency
1npm add pg
1npm add --save-dev node-pg-migrate
Installing this module adds a runnable file into your node_modules/.bin
directory. If installed globally (with the -g option), you can run node-pg-migrate
and if not, you can run ./node_modules/.bin/node-pg-migrate.js
Add "migrate": "node-pg-migrate"
to scripts
section of your package.json
so you are able to quickly run commands.
Run npm run migrate create my-first-migration
. It will create file xxx_my-first-migration.js
in migrations
folder.
Open it and change contents to:
1export const up = (pgm) => {
2 pgm.createTable('users', {
3 id: 'id',
4 name: { type: 'varchar(1000)', notNull: true },
5 createdAt: {
6 type: 'timestamp',
7 notNull: true,
8 default: pgm.func('current_timestamp'),
9 },
10 });
11 pgm.createTable('posts', {
12 id: 'id',
13 userId: {
14 type: 'integer',
15 notNull: true,
16 references: '"users"',
17 onDelete: 'CASCADE',
18 },
19 body: { type: 'text', notNull: true },
20 createdAt: {
21 type: 'timestamp',
22 notNull: true,
23 default: pgm.func('current_timestamp'),
24 },
25 });
26 pgm.createIndex('posts', 'userId');
27};
Save migration file.
Now you should put your DB connection string to DATABASE_URL
environment variable and run npm run migrate up
.
(e.g. DATABASE_URL=postgres://test:test@localhost:5432/test npm run migrate up
)
You should now have two tables in your DB :tada:
If you want to change your schema later, you can e.g. add lead paragraph to posts:
Run npm run migrate create posts_lead
, edit xxx_posts_lead.js
:
1export const up = (pgm) => {
2 pgm.addColumns('posts', {
3 lead: { type: 'text', notNull: true },
4 });
5};
Run npm run migrate up
and there will be a new column in posts
table :tada:
Want to know more? Read docs:
Full docs are available at https://salsita.github.io/node-pg-migrate
Why only Postgres? - By writing this migration tool specifically for postgres instead of accommodating many databases, we can actually provide a full featured tool that is much simpler to use and maintain. I was tired of using crippled database tools just in case one day we switch our database.
Async / Sync - Everything is async in node, and that's great, but a migration tool should really just be a fancy wrapper that generates SQL. Most other migration tools force you to bring in control flow libraries or wrap everything in callbacks as soon as you want to do more than a single operation in a migration. Plus by building up a stack of operations, we can automatically infer down migrations (sometimes) to save even more time.
Naming / Raw Sql - Many tools force you to use their constants to do things like specify data types. Again, this tool should be a fancy wrapper that generates SQL, so whenever possible, it should just pass through user values directly to the SQL. The hard part is remembering the syntax of the specific operation, not remembering how to type "timestamp"!
👋 Welcome, new contributors!
Whether you're a seasoned developer or just getting started, your contributions are valuable to us. Don't hesitate to jump in, explore the project, and make an impact.
No vulnerabilities found.
Reason
30 commit(s) and 9 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
all dependencies are pinned
Details
Reason
license file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
Found 6/13 approved changesets -- score normalized to 4
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More