Gathering detailed insights and metrics for grunt-node-pg-migrate
Gathering detailed insights and metrics for grunt-node-pg-migrate
Gathering detailed insights and metrics for grunt-node-pg-migrate
Gathering detailed insights and metrics for grunt-node-pg-migrate
npm install grunt-node-pg-migrate
Typescript
Module System
Node Version
NPM Version
55
Supply Chain
94.2
Quality
74.3
Maintenance
25
Vulnerability
99.5
License
Cumulative downloads
Total Downloads
Last day
0%
7
Compared to previous day
Last week
0%
7
Compared to previous week
Last month
350%
9
Compared to previous month
Last year
-34.4%
84
Compared to previous year
1
Migrate PostgreSQL database schema and data with node-pg-migrate
Install with npm:
1npm i grunt-node-pg-migrate --save
You may want to start with simple configuration:
1 migrate: { 2 options: { 3 env: { 4 DATABASE_URL: databaseUrl 5 }, 6 verbose: true 7 } 8 }
where databaseUrl
may be exctracted from your environment config like this:
1var CONF = require('config'), 2 databaseUrl = 'postgres://' + CONF.db.user + ':' + CONF.db.password + '@' + CONF.db.host + ':5432/' + CONF.db.name;
Create migration with command line command:
1$ grunt migrate:create:migrate_name
It generates a new file based on template in your 'migrations' folder (see configuration section). For example, edit this file, using async
library:
1/* global exports, require */ 2 3var async = require('async'); 4exports.up = function (db, callback) { 5 async.series([ 6 db.createTable.bind(db, 'users', { 7 id: { 8 type: 'int', 9 primaryKey: true, 10 autoIncrement: true 11 }, 12 email: { 13 type: 'string', 14 unique: true, 15 notNull: true 16 }, 17 password: 'string', 18 created_at: 'datetime', 19 updated_at: 'datetime' 20 }), 21 db.createTable.bind(db, 'items', { 22 id: { 23 type: 'int', 24 primaryKey: true, 25 autoIncrement: true 26 }, 27 user_id: 'int', 28 published: 'boolean', 29 title: 'string' 30 }) 31 ], callback); 32}; 33 34exports.down = function (db, callback) { 35 async.series([ 36 db.dropTable.bind(db, 'users', { 37 ifExists: true 38 }), 39 db.dropTable.bind(db, 'items', { 40 ifExists: true 41 }) 42 ], callback); 43};
And then run the migration step up with grunt migration
command.
migration:up
- run all available migrations up (or just migration
). For example, to update database to specified migration run `grunt migration:up
migration:down
- run one migration down
migration:create:%name%
- create the new migration javascript file from template
env
Environment variables for running db-migrate
.
dir
Default migrations folder is migrations
. But you can choose another:
migrate : {
options: {
dir: 'db/schema-migrations'
}
}
verbose
Verbose output migration process.
You could use any of db-migrate
params.
1 grunt.registerTask('cleandb', 'Clean db and re-apply all migrations', function () { 2 var fs = require('fs'); 3 var files = fs.readdirSync('./migrations'); 4 for (var i = 0; i < files.length; i++) { 5 grunt.task.run('migrate:down'); 6 } 7 grunt.task.run('migrate:up'); 8 });
No vulnerabilities found.
No security vulnerabilities found.