clean up migrations

This commit is contained in:
Josh Harvey 2017-05-07 18:34:46 +03:00
parent 236070668a
commit 279c296aee
8 changed files with 25 additions and 103 deletions

View file

@ -1,46 +1,4 @@
'use strict'
var db = require('./db')
var exchanges = {
exchanges: {
settings: {
commission: 1.0,
compliance: {
maximum: {
limit: null
}
}
},
plugins: {
current: {
BTC: {
ticker: 'bitpay',
transfer: 'bitgo'
},
email: 'smtp2go',
sms: 'twilio',
notify: []
},
settings: {
bitpay: {},
bitgo: {}
}
}
}
}
var unit = {
brain: {
locale: {
currency: 'USD',
localeInfo: {
primaryLocale: 'en-US',
primaryLocales: ['en-US']
}
}
}
}
const db = require('./db')
exports.up = function (next) {
var sqls = [
@ -69,13 +27,7 @@ exports.up = function (next) {
'userName text NOT NULL UNIQUE, ' +
'salt text NOT NULL, ' +
'pwdHash text NOT NULL ' +
')',
'INSERT INTO user_config (type, data) ' +
"VALUES ('exchanges', '" + JSON.stringify(exchanges) + "')",
'INSERT INTO user_config (type, data) ' +
"VALUES ('unit', '" + JSON.stringify(unit) + "')"
')'
]
db.multi(sqls, next)

View file

@ -1,15 +1,14 @@
'use strict';
var db = require('./db')
var db = require('./db');
function singleQuotify (item) { return '\'' + item + '\'' }
function singleQuotify(item) { return '\'' + item + '\''; }
exports.up = function(next) {
exports.up = function (next) {
var stages = ['initial_request', 'partial_request', 'final_request',
'partial_send', 'deposit', 'dispense_request', 'dispense'].
map(singleQuotify).join(',');
'partial_send', 'deposit', 'dispense_request', 'dispense']
.map(singleQuotify).join(',')
var authorizations = ['timeout', 'machine', 'pending', 'rejected',
'published', 'authorized', 'confirmed'].map(singleQuotify).join(',');
'published', 'authorized', 'confirmed'].map(singleQuotify).join(',')
var sqls = [
'CREATE TYPE transaction_stage AS ENUM (' + stages + ')',

View file

@ -3,10 +3,10 @@
var db = require('./db')
exports.up = function (next) {
db.query('CREATE TABLE IF NOT EXISTS machine_configs ( ' +
db.multi(['CREATE TABLE IF NOT EXISTS machine_configs ( ' +
'id serial PRIMARY KEY, ' +
'device_fingerprint text NOT NULL, ' +
'data json NOT NULL )', next)
'data json NOT NULL )'], next)
}
exports.down = function (next) {

View file

@ -3,7 +3,7 @@
var db = require('./db')
exports.up = function (next) {
db.query('CREATE TABLE IF NOT EXISTS cached_responses ( ' +
db.multi(['CREATE TABLE IF NOT EXISTS cached_responses ( ' +
'id serial PRIMARY KEY, ' +
'device_fingerprint text NOT NULL, ' +
'session_id uuid NOT NULL, ' +
@ -12,7 +12,7 @@ exports.up = function (next) {
'body json NOT NULL, ' +
'created timestamptz NOT NULL DEFAULT now(), ' +
'UNIQUE (device_fingerprint, session_id, path, method) ' +
')', next)
')'], next)
}
exports.down = function (next) {

View file

@ -2,7 +2,6 @@ var db = require('./db')
exports.up = function (next) {
var sql = [
'delete from user_config',
'alter table user_config add column valid boolean not null'
]
db.multi(sql, next)

View file

@ -1,43 +1,10 @@
'use strict';
const db = require('../lib/db')
const sequential = require('promise-sequential')
var pg = require('pg');
var async = require('async');
var psqlUrl = require('../lib/options').postgresql
module.exports = {multi}
if (!psqlUrl) {
console.log('No postgresql entry in config file')
process.exit(1)
function multi (sqls, cb) {
return sequential(sqls.map(s => db.none(s)))
.then(cb)
.catch(cb)
}
exports.query = function query(sql, cb) {
exports.multi([sql], cb);
};
exports.silentQuery = function query(sql, cb) {
pg.connect(psqlUrl, function(err, client, done) {
if (err) {
console.log(err.message);
return cb(err);
}
client.query(sql, function(err) {
done(true);
cb(err);
});
});
};
exports.multi = function multi(sqls, cb) {
pg.connect(psqlUrl, function(err, client, done) {
if (err) {
console.log(err.message);
return cb(err);
}
async.eachSeries(sqls, client.query.bind(client), function(err) {
done(true);
if (err) console.log(err);
cb(err);
});
});
};

View file

@ -36,6 +36,7 @@
"pg-promise": "^5.6.4",
"pify": "^2.3.0",
"pretty-ms": "^2.1.0",
"promise-sequential": "^1.1.1",
"ramda": "^0.22.1",
"serve-static": "^1.11.1",
"socket.io": "^1.7.1",

View file

@ -3701,6 +3701,10 @@ process-nextick-args@~1.0.6:
version "1.0.7"
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-1.0.7.tgz#150e20b756590ad3f91093f25a4f2ad8bff30ba3"
promise-sequential@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/promise-sequential/-/promise-sequential-1.1.1.tgz#f79e8950ef86e7a7a85bf320452643592f6d2fb2"
proxy-addr@~1.1.3:
version "1.1.4"
resolved "https://registry.yarnpkg.com/proxy-addr/-/proxy-addr-1.1.4.tgz#27e545f6960a44a627d9b44467e35c1b6b4ce2f3"