Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function performMigration(direction, migrationName) {
var state = join(folderName, '.migrate');
var set = migrate.load(state, folderName);
set.on('migration', function (migration, direction) {
console.log(direction, migration.title);
});
var migrationPath = migrationName ?
join(folderName, migrationName) :
migrationName;
set[direction](migrationName, function (err) {
if (err) {
console.log('error', err);
process.exit(1);
}
console.log('migration', 'complete');
await write(
`insert $x isa MigrationReference,
has internal_id "${uuid()}",
has title "${mig.title}",
has timestamp ${mig.timestamp};`
);
await write(
`match $status isa MigrationStatus;
$ref isa MigrationReference, has title "${mig.title}";
insert (status: $status, state: $ref) isa migrate, has internal_id "${uuid()}";`
);
fn();
}
};
migrate.load({ stateStore: graknStateStorage }, (err, set) => {
if (err) {
throw err;
}
logger.info('Migration state successfully updated, starting migrations');
set.up(err2 => {
if (err2) {
throw err2;
}
logger.info('Migrations successfully ran');
process.exit(0);
});
});
return new Promise((resolve, reject) => {
const migrationsDirectory = path.join(__dirname, '../migrations');
return migrate.load({ stateStore: graknStateStorage, migrationsDirectory }, async (err, set) => {
if (err) reject(err);
logger.info('[MIGRATION] > Migration state successfully updated, starting migrations');
return set.up(err2 => {
if (err2) reject(err2);
logger.info('[MIGRATION] > Migrations successfully ran');
resolve(true);
});
});
});
};