Gathering detailed insights and metrics for @osdiab/node-pg-migrate
Gathering detailed insights and metrics for @osdiab/node-pg-migrate
Gathering detailed insights and metrics for @osdiab/node-pg-migrate
Gathering detailed insights and metrics for @osdiab/node-pg-migrate
npm install @osdiab/node-pg-migrate
Typescript
Module System
Min. Node Version
Node Version
NPM Version
61.8
Supply Chain
99
Quality
74.3
Maintenance
100
Vulnerability
100
License
TypeScript (87.77%)
JavaScript (12.23%)
Total Downloads
3,230
Last Day
1
Last Week
15
Last Month
36
Last Year
2,055
1,304 Stars
1,214 Commits
180 Forks
14 Watching
14 Branches
77 Contributors
Latest Version
6.3.2
Package Id
@osdiab/node-pg-migrate@6.3.2
Unpacked Size
285.82 kB
Size
62.20 kB
File Count
113
NPM Version
8.19.2
Node Version
18.12.1
Publised On
24 Aug 2023
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
50%
15
Compared to previous week
Last month
-53.8%
36
Compared to previous month
Last year
74.9%
2,055
Compared to previous year
4
1
35
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, now maintained by Salsita Software.
see v3 branch.
$ npm install node-pg-migrate pg
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
It will also install pg
library as it is peer dependency used for migrations.
Add "migrate": "node-pg-migrate"
to scripts
section of 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 will 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 new column in posts
table :tada: :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"!
The MIT License (MIT)
Copyright (c) 2016-2021 Salsita Software <jando@salsitasoft.com>
Copyright (c) 2014-2016 Theo Ephraim
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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