Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function main() {
// Execute the migrations
console.log("Running the migrations...");
return migrate.default({
databaseUrl,
migrationsTable,
migrationsSchema,
schema,
direction,
dir
});
}
async _migrateDb() {
let client = new Client(Object.assign({}, config, { database: 'postgres' }));
try {
await client.connect();
let response = await client.query(`select count(*)=1 as has_database from pg_database where datname=$1`, [
config.database,
]);
if (!response.rows[0].has_database) {
await client.query(`create database ${safeDatabaseName(config.database)}`);
}
} finally {
client.end();
}
await migrate({
direction: 'up',
migrationsTable: 'migrations',
singleTransaction: true,
checkOrder: false,
databaseUrl: {
user: config.user,
host: config.host,
database: config.database,
password: config.password,
port: config.port,
},
dir: join(__dirname, 'migrations'),
log: (...args) => log.debug(...args),
});
}
async _runMigrations() {
let config = this.config;
if (!config.migrationsDir) {
return;
}
let dir = path.join(this.projectPath, config.migrationsDir);
await migrate({
direction: 'up',
migrationsTable: 'migrations',
singleTransaction: true,
checkOrder: false,
databaseUrl: {
user: config.user,
host: config.host,
database: config.database,
password: config.password,
port: config.port
},
dir,
log: (...args) => log.debug(...args)
});
}
});
async _migrateDb() {
let client = new Client(Object.assign({}, config, { database: 'postgres' }));
try {
await client.connect();
let response = await client.query(`select count(*)=1 as has_database from pg_database where datname=$1`, [config.database]);
if (!response.rows[0].has_database) {
await client.query(`create database ${this.safeDatabaseName(config.database)}`);
}
} finally {
client.end();
}
await migrate({
direction: 'up',
migrationsTable: 'migrations',
singleTransaction: true,
checkOrder: false,
databaseUrl: {
user: config.user,
host: config.host,
database: config.database,
password: config.password,
port: config.port
},
dir: join(__dirname, 'migrations'),
log: (...args) => log.debug(...args)
});
}
async _migrateDb() {
let client = new Client(Object.assign({}, config, { database: 'postgres' }));
try {
await client.connect();
let response = await client.query(`select count(*)=1 as has_database from pg_database where datname=$1`, [config.database]);
if (!response.rows[0].has_database) {
await client.query(`create database ${safeDatabaseName(config.database)}`);
}
} finally {
client.end();
}
await migrate({
direction: 'up',
migrationsTable: 'migrations',
singleTransaction: true,
checkOrder: false,
databaseUrl: {
user: config.user,
host: config.host,
database: config.database,
password: config.password,
port: config.port
},
dir: join(__dirname, 'migrations'),
log: (...args) => log.debug(...args)
});
}