2016-06-18 21:53:18 +02:00
|
|
|
'use strict';
|
2016-10-26 10:43:11 +02:00
|
|
|
|
2016-06-18 21:53:18 +02:00
|
|
|
const fs = require('fs');
|
|
|
|
const util = require('util');
|
|
|
|
const path = require('path');
|
2014-11-10 15:58:11 +01:00
|
|
|
|
2016-07-02 11:54:50 +02:00
|
|
|
const runMigration = function (migrationPath, db, callback) {
|
2016-06-18 22:23:19 +02:00
|
|
|
db.runSql(fs.readFileSync(migrationPath, { encoding: 'utf8' }), callback);
|
2014-11-10 15:58:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = {
|
2016-07-02 11:54:50 +02:00
|
|
|
create (name) {
|
2016-06-18 21:53:18 +02:00
|
|
|
const format = path.resolve(__dirname, '../migrations/sql/%s.%s.sql');
|
2014-11-10 15:58:11 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
up: runMigration.bind(null, util.format(format, name, 'up')),
|
2016-06-18 21:55:46 +02:00
|
|
|
down: runMigration.bind(null, util.format(format, name, 'down')),
|
2014-11-10 15:58:11 +01:00
|
|
|
};
|
2016-06-18 21:55:46 +02:00
|
|
|
},
|
2014-11-10 15:58:11 +01:00
|
|
|
};
|