Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var postgrator = require('postgrator')
postgrator.setConfig({
migrationDirectory: __dirname + '/migrations',
schemaTable: 'schemaversion', // optional. default is 'schemaversion'
driver: 'pg', // or mysql, mssql
host: '127.0.0.1',
port: 5432, // optionally provide port
database: 'authorization',
username: 'postgres',
password: 'postgres'
})
postgrator.migrate('001', function (err, migrations) {
if (err) {
console.log(err)
} else {
console.log(migrations)
}
postgrator.endConnection(function () {
// connection is closed, or will close in the case of SQL Server
})
})
var applyMigrations = function(migrationId) {
console.log("Target migration = " + migrationId);
postgrator.setMigrationDirectory(__dirname + '/migrations');
postgrator.setConnectionString(process.env.DATABASE_URL || config.db_connection_string);
postgrator.migrate(migrationId, function(err, migrationsRun) {
if (err) {
console.error("Error: " + err);
process.exit(2);
}
});
}
module.exports = function migrate (cb) {
postgrator.setConfig({
migrationDirectory: './scripts/database/pg/migrations',
driver: 'pg',
host: config['postgresql-store'].host,
database: config['postgresql-store'].name,
username: config['postgresql-store'].username,
password: config['postgresql-store'].password
});
postgrator.migrate('max', function (err, migrations) {
postgrator.endConnection(function () {
return cb(err, migrations);
});
});
};
return new Promise(function (resolve, reject) {
postgrator.setConfig({
migrationDirectory: __dirname + '/migrations',
schemaTable: 'xmlforms_migrations',
driver: 'pg',
connectionString: POSTGRESQL_URL
});
postgrator.migrate('201606201000', function(err, migrations) {
if (err) {
reject(err);
} else {
postgrator.endConnection(function() {
resolve(migrations);
});
}
});
});
};
return new rsvp.Promise(function (resolve, reject) {
postgrator.setConfig({
migrationDirectory: __dirname + '/migrations',
schemaTable: 'xmlforms_migrations',
driver: 'pg',
logProgress: log.getLevel() <= log.levels.DEBUG,
connectionString: postgresUrl
});
postgrator.migrate('201606281159', function(err, migrations) {
if (err) {
reject(err);
} else {
postgrator.endConnection(function() {
resolve(migrations);
});
}
});
});
};