
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
migratio-schema
Advanced tools
Automated migrations for Postgres
$ npm install --save migratio
Create directory migrations with migrations and use migratio:
const migratio = require('migratio');
await migratio.current({
connection: 'postgres://localhost/db',
verbose: true
});
// 000005-images.sql (batch:3)
// 000004-files.sql (batch:3)
// 000003-stats.sql (batch:3)
await migratio.up({
connection: 'postgres://localhost/db',
verbose: true
});
// ↑ 000006-posts.sql (batch:4)
await migratio.down({
connection: 'postgres://localhost/db',
verbose: true
});
// ↓ 000005-images.sql (batch:3)
// ↓ 000004-files.sql (batch:3)
// ↓ 000003-stats.sql (batch:3)
All migrations files should start with revision (digits) followed by - and name of migration. For example 000001-init.js and 000002-users.sql is valid file names.
Migrations will be applied in order of numbers in front of filename.
Migration process is running in transaction with lock on migrations table. If one of migrations failed – all batch will be reverted.
Migration file with extension .js is treated as module, that exports two functions:
up – contains code to apply migrationdown – contains code to revert migrationThese functions must return Promise. If these functions are generators, they will be wrapped in co.
exports.up = function * (db) {
yield db.query(`
CREATE TABLE test (
id serial PRIMARY KEY
)
`);
};
exports.down = function * (db) {
yield db.query(`
DROP TABLE IF EXISTS test;
`);
};
Migration file with extension .sql is treated as file with SQL instructions. Instructions to apply migration should be placed after -- +migrate Up and instructions to revert migration should be placed after -- +migrate Down.
-- +migrate Up
CREATE TABLE test (
id serial PRIMARY KEY
);
-- +migrate Down
DROP TABLE IF EXISTS test;
Migratio supports overriding default values with migraio section in package.json:
{
"migratio": {
"directory": "migrations",
"tableName": "migrations"
}
}
Applies all migrations from current to latest available.
Type: string
Default: process.env.DATABASE_URL
Connection string to Postgres database.
Type: Database
Database object. Will be used instead of connection.
Type: string
Default: ./migrations
Directory with migrations.
Type: Number
Default: Infinity
Latest revision to up to.
Type: Boolean
Default: false
Disables meta-table locking.
Type: boolean
Default: false
Enables output.
Type: string
Default: migratio
Table in which migratio will store metadata.
Rollbacks migrations in current batch.
Type: string
Default: process.env.DATABASE_URL
Connection string to Postgres database.
Type: string
Default: ./migrations
Directory with migrations.
Type: Boolean
Default: false
Disables meta-table locking.
Type: boolean
Default: false
Enables output.
Type: string
Default: migratio
Table in which migratio will store metadata.
Shows current batch.
Type: string
Default: process.env.DATABASE_URL
Connection string to Postgres database.
Type: Boolean
Default: false
Disables meta-table locking.
Type: boolean
Default: false
Enables output.
Type: Number
Default: Infinity
First revision to show info about.
Type: string
Default: migratio
Table in which migratio will store metadata.
$ npm install --global migratio
$ migratio --help
Usage
migratio [command] [options]
Options
-d, --directory Directory with migrations files [Default: ./migrations]
-c, --connection Connection string to Postgres [Default: $DATABASE_URL]
-r, --revision Specify revision to up/down to
-t, --table Table name for metadata [Default: migratio]
--unsafe Skip transaction and table locking
Commands
up Applies all migrations from current to latest
down Rollbacks all migrations in current batch
current Shows migrations in current batch
Examples
$ migratio
Current batch:
000005-images.sql (batch:3)
000004-files.sql (batch:3)
000003-stats.sql (batch:3)
$ migratio down
↓ 000005-images.sql (batch:3)
↓ 000004-files.sql (batch:3)
↓ 000003-stats.sql (batch:3)
$ migratio up
↑ 000003-stats.sql (batch:3)
↑ 000004-files.sql (batch:3)
↑ 000005-images.sql (batch:3)
↑ 000006-posts.sql (batch:3)
MIT © Vsevolod Strukchinsky
FAQs
Postgres migrations
We found that migratio-schema demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.