-
Notifications
You must be signed in to change notification settings - Fork 2
/
baseMigration.js
53 lines (47 loc) · 1.41 KB
/
baseMigration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
var dbm;
var type;
var seed;
var fs = require('fs');
var path = require('path');
var Promise;
/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports._setup = function (options, seedLink) {
dbm = options.dbmigrate;
type = dbm.dataType;
seed = seedLink;
Promise = options.Promise;
};
exports._up = function (sql) {
return function (db) {
var filePath = path.join(__dirname, 'migrations/sqls', sql);
return new Promise(function (resolve, reject) {
fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) {
if (err) return reject(err);
console.log('received data: ' + data);
resolve(data);
});
})
.then(function (data) {
return db.runSql(data);
});
};
};
exports._down = function (sql) {
return function (db) {
var filePath = path.join(__dirname, 'migrations/sqls', sql);
return new Promise(function (resolve, reject) {
fs.readFile(filePath, {encoding: 'utf-8'}, function (err, data) {
if (err) return reject(err);
console.log('received data: ' + data);
resolve(data);
});
})
.then(function (data) {
return db.runSql(data);
});
};
};