2016-09-29 18:10:23 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const DBMigrate = require('db-migrate');
|
|
|
|
const path = require('path');
|
|
|
|
|
|
|
|
function findUnleashApiRoot () {
|
|
|
|
try {
|
|
|
|
return path.dirname(require.resolve('unleash-api/package.json'));
|
|
|
|
} catch (e) {}
|
|
|
|
try {
|
2016-09-29 22:50:55 +02:00
|
|
|
return path.dirname(require.resolve('../unleash-api/package.json'));
|
2016-09-29 18:10:23 +02:00
|
|
|
} catch (e) {}
|
|
|
|
return process.cwd();
|
|
|
|
}
|
|
|
|
|
|
|
|
function migrateDb (dbUri) {
|
|
|
|
const dbmigrate = DBMigrate.getInstance(true, {
|
|
|
|
cwd: findUnleashApiRoot(),
|
|
|
|
config: { custom: dbUri },
|
|
|
|
env: 'custom' }
|
|
|
|
);
|
|
|
|
return dbmigrate.up();
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = migrateDb;
|