clean up migrations
This commit is contained in:
parent
393f45a1b3
commit
94ee178c65
4 changed files with 40 additions and 38 deletions
|
|
@ -1,10 +1,8 @@
|
|||
'use strict';
|
||||
|
||||
var db = require('./db');
|
||||
var db = require('./db')
|
||||
|
||||
exports.up = function (next) {
|
||||
var sql =
|
||||
'CREATE TABLE bills ( ' +
|
||||
const sql =
|
||||
['CREATE TABLE bills ( ' +
|
||||
'id uuid PRIMARY KEY, ' +
|
||||
'device_fingerprint text NOT NULL, ' +
|
||||
'denomination integer NOT NULL, ' +
|
||||
|
|
@ -13,13 +11,11 @@ exports.up = function(next) {
|
|||
'to_address text NOT NULL, ' +
|
||||
'session_id uuid NOT NULL, ' +
|
||||
'device_time bigint NOT NULL, ' +
|
||||
'created timestamp NOT NULL DEFAULT now() )';
|
||||
'created timestamp NOT NULL DEFAULT now() )']
|
||||
|
||||
db.silentQuery('ALTER TABLE bills RENAME TO bills_old', function() {
|
||||
db.query(sql, next);
|
||||
});
|
||||
};
|
||||
db.multi(sql, next)
|
||||
}
|
||||
|
||||
exports.down = function (next) {
|
||||
next();
|
||||
};
|
||||
next()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,15 @@
|
|||
'use strict';
|
||||
|
||||
var db = require('./db');
|
||||
var db = require('./db')
|
||||
|
||||
exports.up = function (next) {
|
||||
db.query('CREATE TABLE IF NOT EXISTS machine_events ( ' +
|
||||
db.multi(['CREATE TABLE IF NOT EXISTS machine_events ( ' +
|
||||
'id uuid PRIMARY KEY, ' +
|
||||
'device_fingerprint text NOT NULL, ' +
|
||||
'event_type text NOT NULL, ' +
|
||||
'note text, ' +
|
||||
'device_time bigint NOT NULL, ' +
|
||||
'created timestamp NOT NULL DEFAULT now() )', next);
|
||||
};
|
||||
'created timestamp NOT NULL DEFAULT now() )'], next)
|
||||
}
|
||||
|
||||
exports.down = function (next) {
|
||||
next();
|
||||
};
|
||||
next()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,16 +59,11 @@ exports.up = function (next) {
|
|||
'created timestamp NOT NULL DEFAULT now() ' +
|
||||
')',
|
||||
'CREATE INDEX ON dispenses (device_fingerprint)'
|
||||
];
|
||||
]
|
||||
|
||||
// Need to call this separately to ignore error
|
||||
// in case transactions doesn't exist
|
||||
var renameSql = 'ALTER TABLE transactions RENAME TO transactions_old';
|
||||
db.silentQuery(renameSql, function() {
|
||||
db.multi(sqls, next);
|
||||
});
|
||||
};
|
||||
db.multi(sqls, next)
|
||||
}
|
||||
|
||||
exports.down = function (next) {
|
||||
next();
|
||||
};
|
||||
next()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,20 @@ const sequential = require('promise-sequential')
|
|||
module.exports = {multi}
|
||||
|
||||
function multi (sqls, cb) {
|
||||
return sequential(sqls.map(s => db.none(s)))
|
||||
.then(cb)
|
||||
.catch(cb)
|
||||
const doQuery = s => {
|
||||
return () => {
|
||||
return db.none(s)
|
||||
.catch(err => {
|
||||
console.log(err.stack)
|
||||
throw err
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return sequential(sqls.map(doQuery))
|
||||
.then(() => cb())
|
||||
.catch(err => {
|
||||
console.log(err.stack)
|
||||
cb(err)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue