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) {
|
exports.up = function (next) {
|
||||||
var sql =
|
const sql =
|
||||||
'CREATE TABLE bills ( ' +
|
['CREATE TABLE bills ( ' +
|
||||||
'id uuid PRIMARY KEY, ' +
|
'id uuid PRIMARY KEY, ' +
|
||||||
'device_fingerprint text NOT NULL, ' +
|
'device_fingerprint text NOT NULL, ' +
|
||||||
'denomination integer NOT NULL, ' +
|
'denomination integer NOT NULL, ' +
|
||||||
|
|
@ -13,13 +11,11 @@ exports.up = function(next) {
|
||||||
'to_address text NOT NULL, ' +
|
'to_address text NOT NULL, ' +
|
||||||
'session_id uuid NOT NULL, ' +
|
'session_id uuid NOT NULL, ' +
|
||||||
'device_time bigint 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.multi(sql, next)
|
||||||
db.query(sql, next);
|
}
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.down = function (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) {
|
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, ' +
|
'id uuid PRIMARY KEY, ' +
|
||||||
'device_fingerprint text NOT NULL, ' +
|
'device_fingerprint text NOT NULL, ' +
|
||||||
'event_type text NOT NULL, ' +
|
'event_type text NOT NULL, ' +
|
||||||
'note text, ' +
|
'note text, ' +
|
||||||
'device_time bigint NOT NULL, ' +
|
'device_time bigint NOT NULL, ' +
|
||||||
'created timestamp NOT NULL DEFAULT now() )', next);
|
'created timestamp NOT NULL DEFAULT now() )'], next)
|
||||||
};
|
}
|
||||||
|
|
||||||
exports.down = function (next) {
|
exports.down = function (next) {
|
||||||
next();
|
next()
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -59,16 +59,11 @@ exports.up = function (next) {
|
||||||
'created timestamp NOT NULL DEFAULT now() ' +
|
'created timestamp NOT NULL DEFAULT now() ' +
|
||||||
')',
|
')',
|
||||||
'CREATE INDEX ON dispenses (device_fingerprint)'
|
'CREATE INDEX ON dispenses (device_fingerprint)'
|
||||||
];
|
]
|
||||||
|
|
||||||
// Need to call this separately to ignore error
|
db.multi(sqls, next)
|
||||||
// in case transactions doesn't exist
|
}
|
||||||
var renameSql = 'ALTER TABLE transactions RENAME TO transactions_old';
|
|
||||||
db.silentQuery(renameSql, function() {
|
|
||||||
db.multi(sqls, next);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.down = function (next) {
|
exports.down = function (next) {
|
||||||
next();
|
next()
|
||||||
};
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,20 @@ const sequential = require('promise-sequential')
|
||||||
module.exports = {multi}
|
module.exports = {multi}
|
||||||
|
|
||||||
function multi (sqls, cb) {
|
function multi (sqls, cb) {
|
||||||
return sequential(sqls.map(s => db.none(s)))
|
const doQuery = s => {
|
||||||
.then(cb)
|
return () => {
|
||||||
.catch(cb)
|
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