PostgreSQL migration tool.
pg-migrate
requires node v7.6.0 or higher for ES2015 and async function support.
npm install -g @urbica/pg-migrate
...or build from source
git clone https://github.com/urbica/pg-migrate.git
cd pg-migrate
npm install
Usage:
pg-migrate [options] new <name>
pg-migrate [options] migrate
pg-migrate [options] rollback <N>
pg-migrate [options] reset
pg-migrate --help
pg-migrate --version
Examples:
pg-migrate new create-users
pg-migrate migrate
pg-migrate rollback 1
pg-migrate reset
Options:
--help Show this screen
--version Show version
--verbose Show verbose output
-m --migrations-dir=DIR The directory containing your migration files [default: ./migrations]
-t --migrations-table=TABLE Set the name of the migrations table [default: migrations]
-s --migrations-schema=SCHEMA Set the name of the migrations table scheme [default: public]
Connection options:
-c --connection=DATABASE_URL database connection string in libpq format
-d --db=PGDATABASE database name to connect to
-h --host=PGHOST database server host or socket directory [default: localhost]
-p --port=PGPORT database server port [default: 5432]
-U --user=PGUSER database user name
-W --password=PGPASSWORD database user name password
Using Promises
const PgMigrate = require('@urbica/pg-migrate');
const pgMigrate = new PgMigrate({
database: 'test',
migrationsDir: './migrations'
});
pgMigrate
.connect()
.then(() => pgMigrate.migrate())
.then(() => pgMigrate.end());
...or using async/await
const pgMigrate = new PgMigrate({ database, user, migrationsDir });
async function migrate() {
await pgMigrate.connect();
await pgMigrate.migrate();
await pgMigrate.end();
}
migrate();
See API for more info.