Gathering detailed insights and metrics for node-pg-migrate-exp
Gathering detailed insights and metrics for node-pg-migrate-exp
Gathering detailed insights and metrics for node-pg-migrate-exp
Gathering detailed insights and metrics for node-pg-migrate-exp
npm install node-pg-migrate-exp
Typescript
Module System
Min. Node Version
Node Version
NPM Version
64.8
Supply Chain
99.1
Quality
77.6
Maintenance
100
Vulnerability
100
License
TypeScript (87.77%)
JavaScript (12.23%)
Total Downloads
1,948
Last Day
1
Last Week
2
Last Month
23
Last Year
1,948
1,304 Stars
1,214 Commits
180 Forks
14 Watching
14 Branches
77 Contributors
Minified
Minified + Gzipped
Latest Version
7.4.0-experimental-1189-13
Package Id
node-pg-migrate-exp@7.4.0-experimental-1189-13
Unpacked Size
516.66 kB
Size
90.66 kB
File Count
277
NPM Version
10.8.1
Node Version
21.6.2
Publised On
20 Jun 2024
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-50%
2
Compared to previous week
Last month
-82.3%
23
Compared to previous month
Last year
0%
1,948
Compared to previous year
1
33
The core maintainer of this project moved to @Shinigami92 (also core maintainer of FakerJS and core member of Vite).
The project is and remains under the MIT license.
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:
1exports.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
:
1exports.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"!
No vulnerabilities found.
Reason
22 commit(s) and 3 issue activity found in the last 90 days -- score normalized to 10
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
all dependencies are pinned
Details
Reason
1 existing vulnerabilities detected
Details
Reason
Found 6/10 approved changesets -- score normalized to 6
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 2024-12-16
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