PgMigrate
Parameters
options
Object objectoptions.database
string database to apply migrationsoptions.host
string database host (optional, default'localhost'
)options.port
int database port (optional, default5432
)options.user
string database useroptions.password
string database passwordoptions.schemaName
string database migrations table schema (optional, default'public'
)options.tableName
string database migrations table name (optional, default'migrations'
)options.migrationsDir
string path to migrations dir (optional, default'./migrations'
)options.attachMonitor
boolean attach pg-monitor (optional, defaultfalse
)
Examples
const PgMigrate = require('@urbica/pg-migrate');
const pgMigrate = new PgMigrate({ database: 'test', migrationsDir: './migrations' });
pgMigrate
.connect()
.then(() => pgMigrate.migrate())
.then(() => pgMigrate.end());
Returns Promise
connect prepares database and reads migrations
Examples
const PgMigrate = require('@urbica/pg-migrate');
const pgMigrate = new PgMigrate();
pgMigrate.connect();
Returns Promise
migrate runs migrations
Examples
const PgMigrate = require('@urbica/pg-migrate');
const pgMigrate = new PgMigrate();
pgMigrate
.connect()
.then(() => pgMigrate.migrate());
Returns Promise
rollback rollbacks migrations
Parameters
limit
int number of migrations to rollback (optional, default1
)
Examples
const PgMigrate = require('@urbica/pg-migrate');
const pgMigrate = new PgMigrate();
pgMigrate
.connect()
.then(() => pgMigrate.rollback(1));
Returns Promise
reset rollbacks all migrations
Examples
const PgMigrate = require('@urbica/pg-migrate');
const pgMigrate = new PgMigrate();
pgMigrate
.connect()
.then(() => pgMigrate.reset());
Returns Promise
end closes database connection
Examples
const PgMigrate = require('@urbica/pg-migrate');
const pgMigrate = new PgMigrate();
pgMigrate
.connect()
.then(() => pgMigrate.end());
Returns Promise