Save migrations file on db (#215)
* Revert "Migration sql changes (#199)"
This reverts commit 12c834469c.
* Save migrate file on db
* Add message on migration error in lamassu-update
This commit is contained in:
parent
9af204e609
commit
06f8c57608
58 changed files with 1516 additions and 567 deletions
|
|
@ -1,8 +1,34 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
const FileStore = require('migrate/lib/file-store')
|
||||||
|
|
||||||
|
const db = require('../lib/db')
|
||||||
const migrate = require('../lib/migrate')
|
const migrate = require('../lib/migrate')
|
||||||
|
const options = require('../lib/options')
|
||||||
|
|
||||||
migrate.run()
|
const createMigration = `CREATE TABLE IF NOT EXISTS migrations (
|
||||||
|
id serial PRIMARY KEY,
|
||||||
|
data json NOT NULL
|
||||||
|
)`
|
||||||
|
|
||||||
|
const select = 'select * from migrations limit 1'
|
||||||
|
|
||||||
|
const getMigrateFile = () => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
new FileStore(options.migrateStatePath).load((err, store) => {
|
||||||
|
if (err) return reject(err)
|
||||||
|
return resolve(store)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
db.none(createMigration)
|
||||||
|
.then(() => Promise.all([db.oneOrNone(select), getMigrateFile()]))
|
||||||
|
.then(([qResult, migrateFile]) => {
|
||||||
|
if (!qResult && migrateFile) {
|
||||||
|
return db.none('insert into migrations (id, data) values (1, $1)', [migrateFile])
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(() => migrate.run())
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('DB Migration succeeded.')
|
console.log('DB Migration succeeded.')
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,13 @@ if [ "$(whoami)" != "root" ]; then
|
||||||
exit 3
|
exit 3
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Use a lock file so failed scripts cannot be imediately retried
|
||||||
|
# If not the backup created on this script would be replaced
|
||||||
|
if ! mkdir /var/lock/lamassu-update; then
|
||||||
|
echo "Script is locked because of a failure." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
decho "stopping lamassu-server"
|
decho "stopping lamassu-server"
|
||||||
supervisorctl stop lamassu-server >> ${LOG_FILE} 2>&1
|
supervisorctl stop lamassu-server >> ${LOG_FILE} 2>&1
|
||||||
supervisorctl stop lamassu-admin-server >> ${LOG_FILE} 2>&1
|
supervisorctl stop lamassu-admin-server >> ${LOG_FILE} 2>&1
|
||||||
|
|
@ -53,8 +60,11 @@ decho "rebuilding npm deps"
|
||||||
cd $(npm root -g)/lamassu-server/ >> ${LOG_FILE} 2>&1
|
cd $(npm root -g)/lamassu-server/ >> ${LOG_FILE} 2>&1
|
||||||
npm rebuild >> ${LOG_FILE} 2>&1
|
npm rebuild >> ${LOG_FILE} 2>&1
|
||||||
|
|
||||||
|
{
|
||||||
decho "running migration"
|
decho "running migration"
|
||||||
lamassu-migrate >> ${LOG_FILE} 2>&1
|
lamassu-migrate >> ${LOG_FILE} 2>&1
|
||||||
|
} || { echo "Failure running migrations" ; exit 1 ; }
|
||||||
|
|
||||||
lamassu-migrate-config >> ${LOG_FILE} 2>&1
|
lamassu-migrate-config >> ${LOG_FILE} 2>&1
|
||||||
|
|
||||||
decho "update to mnemonic"
|
decho "update to mnemonic"
|
||||||
|
|
@ -88,4 +98,6 @@ set -e
|
||||||
# reset terminal to link new executables
|
# reset terminal to link new executables
|
||||||
hash -r
|
hash -r
|
||||||
|
|
||||||
|
rm -r /var/lock/lamassu-update
|
||||||
|
|
||||||
decho "Update complete!"
|
decho "Update complete!"
|
||||||
|
|
|
||||||
22
lib/db-migrate-store.js
Normal file
22
lib/db-migrate-store.js
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
const db = require('../lib/db')
|
||||||
|
|
||||||
|
const upsert = 'insert into migrations (id, data) values (1, $1) on conflict (id) do update set data = $1'
|
||||||
|
|
||||||
|
function DbMigrateStore () {
|
||||||
|
}
|
||||||
|
|
||||||
|
DbMigrateStore.prototype.save = function (set, fn) {
|
||||||
|
let insertData = JSON.stringify({
|
||||||
|
lastRun: set.lastRun,
|
||||||
|
migrations: set.migrations
|
||||||
|
})
|
||||||
|
db.none(upsert, [insertData]).then(fn).catch(err => console.log(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
DbMigrateStore.prototype.load = function (fn) {
|
||||||
|
db.one('select data from migrations').then(({ data }) => {
|
||||||
|
fn(null, data)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = DbMigrateStore
|
||||||
|
|
@ -1,18 +1,24 @@
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const migrate = require('migrate')
|
const migrate = require('migrate')
|
||||||
|
|
||||||
const options = require('./options')
|
const DbMigrateStore = require('./db-migrate-store')
|
||||||
|
|
||||||
const migrateDir = path.resolve(__dirname, '..', 'migrations')
|
const migrateDir = path.resolve(__dirname, '..', 'migrations')
|
||||||
const migration = migrate.load(options.migrateStatePath, migrateDir)
|
const migrateOpts = {
|
||||||
|
migrationsDirectory: migrateDir,
|
||||||
module.exports = {run}
|
stateStore: new DbMigrateStore(),
|
||||||
|
filterFunction: it => it.match(/^\d+.*\.js$/)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { run }
|
||||||
function run () {
|
function run () {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
migration.up(err => {
|
migrate.load(migrateOpts, (err, set) => {
|
||||||
if (err) return reject(err)
|
if (err) return reject(err)
|
||||||
return resolve(0)
|
set.up(err => {
|
||||||
|
if (err) return reject(err)
|
||||||
|
return resolve(0)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,30 +3,30 @@ const db = require('./db')
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sqls = [
|
var sqls = [
|
||||||
'CREATE TABLE IF NOT EXISTS user_config ( ' +
|
'CREATE TABLE IF NOT EXISTS user_config ( ' +
|
||||||
'id serial PRIMARY KEY, ' +
|
'id serial PRIMARY KEY, ' +
|
||||||
'type text NOT NULL, ' +
|
'type text NOT NULL, ' +
|
||||||
'data json NOT NULL ' +
|
'data json NOT NULL ' +
|
||||||
')',
|
')',
|
||||||
|
|
||||||
'CREATE TABLE IF NOT EXISTS devices ( ' +
|
'CREATE TABLE IF NOT EXISTS devices ( ' +
|
||||||
'id serial PRIMARY KEY, ' +
|
'id serial PRIMARY KEY, ' +
|
||||||
'fingerprint text NOT NULL UNIQUE, ' +
|
'fingerprint text NOT NULL UNIQUE, ' +
|
||||||
'name text, ' +
|
'name text, ' +
|
||||||
'authorized boolean, ' +
|
'authorized boolean, ' +
|
||||||
'unpair boolean NOT NULL DEFAULT false' +
|
'unpair boolean NOT NULL DEFAULT false' +
|
||||||
')',
|
')',
|
||||||
|
|
||||||
'CREATE TABLE IF NOT EXISTS pairing_tokens (' +
|
'CREATE TABLE IF NOT EXISTS pairing_tokens (' +
|
||||||
'id serial PRIMARY KEY, ' +
|
'id serial PRIMARY KEY, ' +
|
||||||
'token text, ' +
|
'token text, ' +
|
||||||
'created timestamp NOT NULL DEFAULT now() ' +
|
'created timestamp NOT NULL DEFAULT now() ' +
|
||||||
')',
|
')',
|
||||||
|
|
||||||
'CREATE TABLE IF NOT EXISTS users ( ' +
|
'CREATE TABLE IF NOT EXISTS users ( ' +
|
||||||
'id serial PRIMARY KEY, ' +
|
'id serial PRIMARY KEY, ' +
|
||||||
'userName text NOT NULL UNIQUE, ' +
|
'userName text NOT NULL UNIQUE, ' +
|
||||||
'salt text NOT NULL, ' +
|
'salt text NOT NULL, ' +
|
||||||
'pwdHash text NOT NULL ' +
|
'pwdHash text NOT NULL ' +
|
||||||
')'
|
')'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,17 +2,16 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const sql =
|
const sql =
|
||||||
['CREATE TABLE IF NOT EXISTS 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, ' +
|
||||||
'currency_code text NOT NULL, ' +
|
'currency_code text NOT NULL, ' +
|
||||||
'satoshis integer NOT NULL, ' +
|
'satoshis integer NOT NULL, ' +
|
||||||
'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.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,7 @@ exports.up = function (next) {
|
||||||
'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() ' +
|
'created timestamp NOT NULL DEFAULT now() )'], next)
|
||||||
')'], next)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.down = function (next) {
|
exports.down = function (next) {
|
||||||
|
|
|
||||||
|
|
@ -11,54 +11,54 @@ exports.up = function (next) {
|
||||||
'published', 'authorized', 'confirmed'].map(singleQuotify).join(',')
|
'published', 'authorized', 'confirmed'].map(singleQuotify).join(',')
|
||||||
|
|
||||||
var sqls = [
|
var sqls = [
|
||||||
db.defineEnum('transaction_stage', stages),
|
'CREATE TYPE transaction_stage AS ENUM (' + stages + ')',
|
||||||
db.defineEnum('transaction_authority', authorizations),
|
'CREATE TYPE transaction_authority AS ENUM (' + authorizations + ')',
|
||||||
|
|
||||||
'CREATE TABLE IF NOT EXISTS transactions ( ' +
|
'CREATE TABLE transactions ( ' +
|
||||||
'id serial PRIMARY KEY, ' +
|
'id serial PRIMARY KEY, ' +
|
||||||
'session_id uuid NOT NULL, ' +
|
'session_id uuid NOT NULL, ' +
|
||||||
'device_fingerprint text, ' +
|
'device_fingerprint text, ' +
|
||||||
'to_address text NOT NULL, ' +
|
'to_address text NOT NULL, ' +
|
||||||
'satoshis integer NOT NULL DEFAULT 0, ' +
|
'satoshis integer NOT NULL DEFAULT 0, ' +
|
||||||
'fiat integer NOT NULL DEFAULT 0, ' +
|
'fiat integer NOT NULL DEFAULT 0, ' +
|
||||||
'currency_code text NOT NULL, ' +
|
'currency_code text NOT NULL, ' +
|
||||||
'fee integer NOT NULL DEFAULT 0, ' +
|
'fee integer NOT NULL DEFAULT 0, ' +
|
||||||
'incoming boolean NOT NULL, ' +
|
'incoming boolean NOT NULL, ' +
|
||||||
'stage transaction_stage NOT NULL, ' +
|
'stage transaction_stage NOT NULL, ' +
|
||||||
'authority transaction_authority NOT NULL, ' +
|
'authority transaction_authority NOT NULL, ' +
|
||||||
'tx_hash text, ' +
|
'tx_hash text, ' +
|
||||||
'error text, ' +
|
'error text, ' +
|
||||||
'created timestamp NOT NULL DEFAULT now(), ' +
|
'created timestamp NOT NULL DEFAULT now(), ' +
|
||||||
'UNIQUE (session_id, to_address, stage, authority) ' +
|
'UNIQUE (session_id, to_address, stage, authority) ' +
|
||||||
')',
|
')',
|
||||||
'CREATE INDEX ON transactions (session_id)',
|
'CREATE INDEX ON transactions (session_id)',
|
||||||
|
|
||||||
'CREATE TABLE IF NOT EXISTS pending_transactions ( ' +
|
'CREATE TABLE pending_transactions ( ' +
|
||||||
'id serial PRIMARY KEY, ' +
|
'id serial PRIMARY KEY, ' +
|
||||||
'device_fingerprint text NOT NULL, ' +
|
'device_fingerprint text NOT NULL, ' +
|
||||||
'session_id uuid UNIQUE NOT NULL, ' +
|
'session_id uuid UNIQUE NOT NULL, ' +
|
||||||
'incoming boolean NOT NULL, ' +
|
'incoming boolean NOT NULL, ' +
|
||||||
'currency_code text NOT NULL, ' +
|
'currency_code text NOT NULL, ' +
|
||||||
'to_address text NOT NULL, ' +
|
'to_address text NOT NULL, ' +
|
||||||
'satoshis integer NOT NULL, ' +
|
'satoshis integer NOT NULL, ' +
|
||||||
'updated timestamp NOT NULL DEFAULT now() ' +
|
'updated timestamp NOT NULL DEFAULT now() ' +
|
||||||
')',
|
')',
|
||||||
|
|
||||||
'CREATE TABLE IF NOT EXISTS dispenses ( ' +
|
'CREATE TABLE dispenses ( ' +
|
||||||
'id serial PRIMARY KEY, ' +
|
'id serial PRIMARY KEY, ' +
|
||||||
'device_fingerprint text NOT NULL, ' +
|
'device_fingerprint text NOT NULL, ' +
|
||||||
'transaction_id integer UNIQUE REFERENCES transactions(id), ' +
|
'transaction_id integer UNIQUE REFERENCES transactions(id), ' +
|
||||||
'dispense1 integer NOT NULL, ' +
|
'dispense1 integer NOT NULL, ' +
|
||||||
'reject1 integer NOT NULL, ' +
|
'reject1 integer NOT NULL, ' +
|
||||||
'count1 integer NOT NULL, ' +
|
'count1 integer NOT NULL, ' +
|
||||||
'dispense2 integer NOT NULL, ' +
|
'dispense2 integer NOT NULL, ' +
|
||||||
'reject2 integer NOT NULL, ' +
|
'reject2 integer NOT NULL, ' +
|
||||||
'count2 integer NOT NULL, ' +
|
'count2 integer NOT NULL, ' +
|
||||||
'refill boolean NOT NULL, ' +
|
'refill boolean NOT NULL, ' +
|
||||||
'error text, ' +
|
'error text, ' +
|
||||||
'created timestamp NOT NULL DEFAULT now() ' +
|
'created timestamp NOT NULL DEFAULT now() ' +
|
||||||
')',
|
')',
|
||||||
db.ifColumn('dispenses', 'device_fingerprint', 'CREATE INDEX ON dispenses (device_fingerprint)')
|
'CREATE INDEX ON dispenses (device_fingerprint)'
|
||||||
]
|
]
|
||||||
|
|
||||||
db.multi(sqls, next)
|
db.multi(sqls, next)
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sqls = [
|
var sqls = [
|
||||||
db.alterColumn('transactions', 'satoshis', 'TYPE bigint'),
|
'alter table transactions alter satoshis TYPE bigint',
|
||||||
db.addColumn('transactions', 'crypto_code', 'text default \'BTC\''),
|
"alter table transactions add crypto_code text default 'BTC'",
|
||||||
db.addColumn('pending_transactions', 'crypto_code', 'text default \'BTC\''),
|
"alter table pending_transactions add crypto_code text default 'BTC'",
|
||||||
db.alterColumn('pending_transactions', 'satoshis', 'TYPE bigint'),
|
'alter table pending_transactions alter satoshis TYPE bigint',
|
||||||
db.addColumn('bills', 'crypto_code', 'text default \'BTC\''),
|
"alter table bills add crypto_code text default 'BTC'",
|
||||||
db.alterColumn('bills', 'satoshis', 'TYPE bigint')
|
'alter table bills alter satoshis TYPE bigint'
|
||||||
]
|
]
|
||||||
|
|
||||||
db.multi(sqls, next)
|
db.multi(sqls, next)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.addColumn('transactions', 'phone', 'text'),
|
'alter table transactions add phone text',
|
||||||
'create index on transactions (phone)'
|
'create index on transactions (phone)'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,12 @@ exports.up = function (next) {
|
||||||
.map(singleQuotify).join(',')
|
.map(singleQuotify).join(',')
|
||||||
|
|
||||||
var sql = [
|
var sql = [
|
||||||
db.defineEnum('status_stage', statuses),
|
'create type status_stage AS enum (' + statuses + ')',
|
||||||
db.addColumn('transactions', 'dispensed', 'boolean NOT NULL DEFAULT false'),
|
'alter table transactions add dispensed boolean NOT NULL DEFAULT false',
|
||||||
db.addColumn('transactions', 'notified', 'boolean NOT NULL DEFAULT false'),
|
'alter table transactions add notified boolean NOT NULL DEFAULT false',
|
||||||
db.addColumn('transactions', 'redeem', 'boolean NOT NULL DEFAULT false'),
|
'alter table transactions add redeem boolean NOT NULL DEFAULT false',
|
||||||
db.addColumn('transactions', 'confirmation_time', 'timestamptz'),
|
'alter table transactions add confirmation_time timestamptz',
|
||||||
db.addColumn('transactions', 'status', 'status_stage NOT NULL DEFAULT \'notSeen\'')
|
'alter table transactions add status status_stage NOT NULL DEFAULT \'notSeen\''
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.alterColumn('transactions', 'created', 'type timestamptz'),
|
'alter table transactions alter created type timestamptz',
|
||||||
db.alterColumn('bills', 'created', 'type timestamptz'),
|
'alter table bills alter created type timestamptz',
|
||||||
db.alterColumn('dispenses', 'created', 'type timestamptz'),
|
'alter table dispenses alter created type timestamptz',
|
||||||
db.alterColumn('machine_events', 'created', 'type timestamptz'),
|
'alter table machine_events alter created type timestamptz',
|
||||||
db.alterColumn('pairing_tokens', 'created', 'type timestamptz'),
|
'alter table pairing_tokens alter created type timestamptz',
|
||||||
db.alterColumn('pending_transactions', 'updated', 'type timestamptz')
|
'alter table pending_transactions alter updated type timestamptz'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,14 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
db.multi(['CREATE TABLE IF NOT EXISTS cached_responses ( ' +
|
db.multi(['CREATE TABLE IF NOT EXISTS cached_responses ( ' +
|
||||||
'id serial PRIMARY KEY, ' +
|
'id serial PRIMARY KEY, ' +
|
||||||
'device_fingerprint text NOT NULL, ' +
|
'device_fingerprint text NOT NULL, ' +
|
||||||
'session_id uuid NOT NULL, ' +
|
'session_id uuid NOT NULL, ' +
|
||||||
'path text NOT NULL, ' +
|
'path text NOT NULL, ' +
|
||||||
'method text NOT NULL, ' +
|
'method text NOT NULL, ' +
|
||||||
'body json NOT NULL, ' +
|
'body json NOT NULL, ' +
|
||||||
'created timestamptz NOT NULL DEFAULT now(), ' +
|
'created timestamptz NOT NULL DEFAULT now(), ' +
|
||||||
'UNIQUE (device_fingerprint, session_id, path, method) ' +
|
'UNIQUE (device_fingerprint, session_id, path, method) ' +
|
||||||
')'], next)
|
')'], next)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ exports.up = function (next) {
|
||||||
.map(singleQuotify).join(',')
|
.map(singleQuotify).join(',')
|
||||||
|
|
||||||
var sql = [
|
var sql = [
|
||||||
`CREATE TABLE IF NOT EXISTS cash_in_txs (
|
`create table cash_in_txs (
|
||||||
session_id uuid PRIMARY KEY,
|
session_id uuid PRIMARY KEY,
|
||||||
device_fingerprint text NOT NULL,
|
device_fingerprint text NOT NULL,
|
||||||
to_address text NOT NULL,
|
to_address text NOT NULL,
|
||||||
|
|
@ -23,7 +23,7 @@ exports.up = function (next) {
|
||||||
error text,
|
error text,
|
||||||
created timestamptz NOT NULL default now()
|
created timestamptz NOT NULL default now()
|
||||||
)`,
|
)`,
|
||||||
`CREATE TABLE IF NOT EXISTS cash_out_txs (
|
`create table cash_out_txs (
|
||||||
session_id uuid PRIMARY KEY,
|
session_id uuid PRIMARY KEY,
|
||||||
device_fingerprint text NOT NULL,
|
device_fingerprint text NOT NULL,
|
||||||
to_address text NOT NULL,
|
to_address text NOT NULL,
|
||||||
|
|
@ -32,7 +32,7 @@ exports.up = function (next) {
|
||||||
fiat numeric(14, 5) NOT NULL,
|
fiat numeric(14, 5) NOT NULL,
|
||||||
currency_code text NOT NULL,
|
currency_code text NOT NULL,
|
||||||
tx_hash text,
|
tx_hash text,
|
||||||
status status_stage NOT NULL default 'notSeen',
|
status status_stage NOT NULL default \'notSeen\',
|
||||||
dispensed boolean NOT NULL default false,
|
dispensed boolean NOT NULL default false,
|
||||||
notified boolean NOT NULL default false,
|
notified boolean NOT NULL default false,
|
||||||
redeem boolean NOT NULL default false,
|
redeem boolean NOT NULL default false,
|
||||||
|
|
@ -41,16 +41,15 @@ exports.up = function (next) {
|
||||||
created timestamptz NOT NULL default now(),
|
created timestamptz NOT NULL default now(),
|
||||||
confirmation_time timestamptz
|
confirmation_time timestamptz
|
||||||
)`,
|
)`,
|
||||||
db.defineEnum('cash_out_action_types', actions),
|
`create type cash_out_action_types AS ENUM (${actions})`,
|
||||||
`CREATE TABLE IF NOT EXISTS cash_out_actions (
|
`create table cash_out_actions (
|
||||||
id serial PRIMARY KEY,
|
id serial PRIMARY KEY,
|
||||||
session_id uuid,
|
session_id uuid REFERENCES cash_out_txs(session_id),
|
||||||
action cash_out_action_types NOT NULL,
|
action cash_out_action_types NOT NULL,
|
||||||
created timestamptz NOT NULL default now()
|
created timestamptz NOT NULL default now()
|
||||||
)`,
|
)`,
|
||||||
db.addConstraint('cash_out_actions', 'cash_out_actions_session_id_fkey', 'FOREIGN KEY (session_id) REFERENCES cash_out_txs(session_id)', 'cash_out_txs', 'session_id'),
|
`alter table dispenses add session_id uuid`,
|
||||||
db.addColumn('dispenses', 'session_id', 'uuid'),
|
`alter table dispenses drop constraint dispenses_transaction_id_fkey`
|
||||||
db.dropConstraint('dispenses', 'dispenses_transaction_id_fkey')
|
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
`CREATE TABLE IF NOT EXISTS cash_out_hds (
|
`create table cash_out_hds (
|
||||||
session_id uuid PRIMARY KEY,
|
session_id uuid PRIMARY KEY,
|
||||||
crypto_code text NOT NULL,
|
crypto_code text NOT NULL,
|
||||||
hd_serial integer NOT NULL,
|
hd_serial integer NOT NULL,
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.addColumn('cash_out_hds', 'last_checked', 'timestamptz not null default now()'),
|
'alter table cash_out_hds add last_checked timestamptz not null default now()',
|
||||||
db.addColumn('cash_out_hds', 'confirmed', 'boolean not null default false'),
|
'alter table cash_out_hds add confirmed boolean not null default false',
|
||||||
'create index on cash_out_hds (confirmed, last_checked)'
|
'create index on cash_out_hds (confirmed, last_checked)'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
|
|
|
||||||
|
|
@ -2,31 +2,31 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.renameColumn('bills', 'device_fingerprint', 'device_id'),
|
'alter table bills rename device_fingerprint to device_id',
|
||||||
db.renameColumn('bills', 'satoshis', 'crypto_atoms'),
|
'alter table bills rename satoshis to crypto_atoms',
|
||||||
db.renameColumn('bills', 'session_id', 'cash_in_txs_id'),
|
'alter table bills rename session_id to cash_in_txs_id',
|
||||||
|
|
||||||
db.renameColumn('cached_responses', 'device_fingerprint', 'device_id'),
|
'alter table cached_responses rename device_fingerprint to device_id',
|
||||||
db.renameColumn('cached_responses', 'session_id', 'tx_id'),
|
'alter table cached_responses rename session_id to tx_id',
|
||||||
|
|
||||||
db.renameColumn('cash_in_txs', 'session_id', 'id'),
|
'alter table cash_in_txs rename session_id to id',
|
||||||
db.renameColumn('cash_in_txs', 'device_fingerprint', 'device_id'),
|
'alter table cash_in_txs rename device_fingerprint to device_id',
|
||||||
|
|
||||||
db.renameColumn('cash_out_actions', 'session_id', 'cash_out_txs_id'),
|
'alter table cash_out_actions rename session_id to cash_out_txs_id',
|
||||||
|
|
||||||
db.renameColumn('cash_out_hds', 'session_id', 'id'),
|
'alter table cash_out_hds rename session_id to id',
|
||||||
|
|
||||||
db.renameColumn('cash_out_txs', 'session_id', 'id'),
|
'alter table cash_out_txs rename session_id to id',
|
||||||
db.renameColumn('cash_out_txs', 'device_fingerprint', 'device_id'),
|
'alter table cash_out_txs rename device_fingerprint to device_id',
|
||||||
|
|
||||||
db.renameColumn('devices', 'fingerprint', 'device_id'),
|
'alter table devices rename fingerprint to device_id',
|
||||||
|
|
||||||
db.renameColumn('dispenses', 'session_id', 'cash_out_txs_id'),
|
'alter table dispenses rename session_id to cash_out_txs_id',
|
||||||
db.renameColumn('dispenses', 'device_fingerprint', 'device_id'),
|
'alter table dispenses rename device_fingerprint to device_id',
|
||||||
|
|
||||||
db.renameColumn('machine_configs', 'device_fingerprint', 'device_id'),
|
'alter table machine_configs rename device_fingerprint to device_id',
|
||||||
|
|
||||||
db.renameColumn('machine_events', 'device_fingerprint', 'device_id')
|
'alter table machine_events rename device_fingerprint to device_id'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.dropColumn('devices', 'authorized'),
|
'alter table devices drop authorized',
|
||||||
db.dropColumn('devices', 'unpair'),
|
'alter table devices drop unpair',
|
||||||
`CREATE TABLE IF NOT EXISTS paired_devices (
|
`create table paired_devices (
|
||||||
device_id text PRIMARY KEY,
|
device_id text PRIMARY KEY,
|
||||||
created timestamptz NOT NULL default now()
|
created timestamptz NOT NULL default now()
|
||||||
)`
|
)`
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ var db = require('./db')
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
'drop table if exists cached_responses',
|
'drop table if exists cached_responses',
|
||||||
`create table if not exists idempotents (
|
`create table idempotents (
|
||||||
request_id text PRIMARY KEY,
|
request_id text PRIMARY KEY,
|
||||||
device_id text NOT NULL,
|
device_id text NOT NULL,
|
||||||
body json NOT NULL,
|
body json NOT NULL,
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@ var db = require('./db')
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
'drop table if exists users',
|
'drop table if exists users',
|
||||||
`create table if not exists user_tokens (
|
`create table user_tokens (
|
||||||
token text PRIMARY KEY,
|
token text PRIMARY KEY,
|
||||||
name text NOT NULL,
|
name text NOT NULL,
|
||||||
created timestamptz NOT NULL default now()
|
created timestamptz NOT NULL default now()
|
||||||
)`,
|
)`,
|
||||||
`create table if not exists one_time_passes (
|
`create table one_time_passes (
|
||||||
token text PRIMARY KEY,
|
token text PRIMARY KEY,
|
||||||
name text NOT NULL,
|
name text NOT NULL,
|
||||||
created timestamptz NOT NULL default now()
|
created timestamptz NOT NULL default now()
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
'drop table if exists devices',
|
'drop table if exists devices',
|
||||||
'drop table if exists paired_devices',
|
'drop table if exists paired_devices',
|
||||||
`create table if not exists devices (
|
`create table devices (
|
||||||
device_id text PRIMARY KEY,
|
device_id text PRIMARY KEY,
|
||||||
name text NOT NULL,
|
name text NOT NULL,
|
||||||
cashbox integer NOT NULL default 0,
|
cashbox integer NOT NULL default 0,
|
||||||
|
|
@ -14,7 +14,7 @@ exports.up = function (next) {
|
||||||
display boolean NOT NULL default TRUE,
|
display boolean NOT NULL default TRUE,
|
||||||
created timestamptz NOT NULL default now()
|
created timestamptz NOT NULL default now()
|
||||||
)`,
|
)`,
|
||||||
db.addColumn('pairing_tokens', 'name', 'text NOT NULL')
|
'alter table pairing_tokens add column name text NOT NULL'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,9 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.dropColumn('dispenses', 'count1'),
|
'alter table dispenses drop column count1',
|
||||||
db.dropColumn('dispenses', 'count2'),
|
'alter table dispenses drop column count2',
|
||||||
db.dropColumn('dispenses', 'refill')
|
'alter table dispenses drop column refill'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
`create table if not exists server_events (
|
`create table server_events (
|
||||||
id serial PRIMARY KEY,
|
id serial PRIMARY KEY,
|
||||||
event_type text NOT NULL,
|
event_type text NOT NULL,
|
||||||
created timestamptz NOT NULL default now()
|
created timestamptz NOT NULL default now()
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,11 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.addColumn('devices', 'user_config_id', 'int'),
|
'alter table devices add column user_config_id int',
|
||||||
db.addColumn('user_config', 'created', 'timestamptz NOT NULL default now()'),
|
'alter table user_config add column created timestamptz NOT NULL default now()',
|
||||||
db.addConstraint('devices', 'user_config_id', 'FOREIGN KEY (user_config_id) REFERENCES user_config (id)')
|
`ALTER TABLE devices ADD CONSTRAINT user_config_id
|
||||||
|
FOREIGN KEY (user_config_id)
|
||||||
|
REFERENCES user_config (id)`
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.addColumn('cash_in_txs', 'send', 'boolean not null default false'),
|
'alter table cash_in_txs add column send boolean not null default false',
|
||||||
db.renameColumn('cash_in_txs', 'currency_code', 'fiat_code'),
|
'alter table cash_in_txs rename currency_code to fiat_code',
|
||||||
db.renameColumn('bills', 'currency_code', 'fiat_code'),
|
'alter table bills rename currency_code to fiat_code',
|
||||||
db.renameColumn('bills', 'denomination', 'fiat'),
|
'alter table bills rename denomination to fiat',
|
||||||
db.dropColumn('bills', 'to_address'),
|
'alter table bills drop column to_address',
|
||||||
db.dropColumn('bills', 'device_id'),
|
'alter table bills drop column device_id',
|
||||||
db.renameColumn('cash_out_txs', 'currency_code', 'fiat_code')
|
'alter table cash_out_txs rename currency_code to fiat_code'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,15 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.addColumn('cash_out_txs', 'dispensed_1', 'integer'),
|
'alter table cash_out_txs add column dispensed_1 integer',
|
||||||
db.addColumn('cash_out_txs', 'dispensed_2', 'integer'),
|
'alter table cash_out_txs add column dispensed_2 integer',
|
||||||
db.addColumn('cash_out_txs', 'rejected_1', 'integer'),
|
'alter table cash_out_txs add column rejected_1 integer',
|
||||||
db.addColumn('cash_out_txs', 'rejected_2', 'integer'),
|
'alter table cash_out_txs add column rejected_2 integer',
|
||||||
db.addColumn('cash_out_txs', 'denomination_1', 'integer'),
|
'alter table cash_out_txs add column denomination_1 integer',
|
||||||
db.addColumn('cash_out_txs', 'denomination_2', 'integer'),
|
'alter table cash_out_txs add column denomination_2 integer',
|
||||||
db.addColumn('cash_out_txs', 'dispense_error', 'text'),
|
'alter table cash_out_txs add column dispense_error text',
|
||||||
db.addColumn('cash_out_txs', 'dispense_time', 'timestamptz'),
|
'alter table cash_out_txs add column dispense_time timestamptz',
|
||||||
'drop table if exists dispenses'
|
'drop table dispenses'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,18 +2,18 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.addSequence('hd_indices_seq', 'minvalue 0 maxvalue 2147483647'),
|
'create sequence hd_indices_seq minvalue 0 maxvalue 2147483647',
|
||||||
db.addColumn('cash_out_txs', 'hd_index', 'integer'),
|
'alter table cash_out_txs add column hd_index integer',
|
||||||
db.alterSequence('hd_indices_seq', 'owned by cash_out_txs.hd_index'),
|
'alter sequence hd_indices_seq owned by cash_out_txs.hd_index',
|
||||||
db.addColumn('cash_out_txs', 'swept', 'boolean not null default \'f\''),
|
"alter table cash_out_txs add column swept boolean not null default 'f'",
|
||||||
db.dropColumn('cash_out_txs', 'tx_hash'),
|
'alter table cash_out_txs drop column tx_hash',
|
||||||
'create unique index on cash_out_txs (hd_index)',
|
'create unique index on cash_out_txs (hd_index)',
|
||||||
'drop table if exists cash_out_hds',
|
'drop table cash_out_hds',
|
||||||
'drop table if exists cash_out_actions',
|
'drop table cash_out_actions',
|
||||||
'drop table if exists transactions',
|
'drop table transactions',
|
||||||
'drop table if exists idempotents',
|
'drop table idempotents',
|
||||||
'drop table if exists machine_configs',
|
'drop table machine_configs',
|
||||||
'drop table if exists pending_transactions'
|
'drop table pending_transactions'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.defineEnum('trade_type', "'buy', 'sell'"),
|
"create type trade_type as enum ('buy', 'sell')",
|
||||||
`create table if not exists trades (
|
`create table trades (
|
||||||
id serial PRIMARY KEY,
|
id serial PRIMARY KEY,
|
||||||
type trade_type not null,
|
type trade_type not null,
|
||||||
crypto_code text not null,
|
crypto_code text not null,
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,15 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.addColumn('cash_in_txs', 'send_confirmed', 'boolean not null default false'),
|
'alter table cash_in_txs add column send_confirmed boolean not null default false',
|
||||||
db.addColumn('cash_in_txs', 'device_time', 'bigint not null'),
|
'alter table cash_in_txs add column device_time bigint not null',
|
||||||
db.addColumn('cash_in_txs', 'timedout', 'boolean not null default false'),
|
'alter table cash_in_txs add column timedout boolean not null default false',
|
||||||
db.addColumn('cash_in_txs', 'send_time', 'timestamptz'),
|
'alter table cash_in_txs add column send_time timestamptz',
|
||||||
db.addColumn('cash_in_txs', 'error_code', 'text'),
|
'alter table cash_in_txs add column error_code text',
|
||||||
db.addColumn('cash_in_txs', 'operator_completed', 'boolean not null default false'),
|
'alter table cash_in_txs add column operator_completed boolean not null default false',
|
||||||
db.addColumn('cash_in_txs', 'send_pending', 'boolean not null default false'),
|
'alter table cash_in_txs add column send_pending boolean not null default false',
|
||||||
db.addColumn('cash_out_txs', 'device_time', 'bigint not null'),
|
'alter table cash_out_txs add column device_time bigint not null',
|
||||||
db.addColumn('cash_out_txs', 'timedout', 'boolean not null default false')
|
'alter table cash_out_txs add column timedout boolean not null default false'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
`create table if not exists cash_in_actions (
|
`create table cash_in_actions (
|
||||||
id serial primary key,
|
id serial primary key,
|
||||||
tx_id uuid not null,
|
tx_id uuid not null,
|
||||||
action text not null,
|
action text not null,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
`create table if not exists cash_out_actions (
|
`create table cash_out_actions (
|
||||||
id serial primary key,
|
id serial primary key,
|
||||||
tx_id uuid not null,
|
tx_id uuid not null,
|
||||||
action text not null,
|
action text not null,
|
||||||
|
|
@ -22,16 +22,16 @@ exports.up = function (next) {
|
||||||
device_time bigint,
|
device_time bigint,
|
||||||
created timestamptz not null default now()
|
created timestamptz not null default now()
|
||||||
)`,
|
)`,
|
||||||
db.dropColumn('cash_out_txs', 'dispensed_1'),
|
'alter table cash_out_txs drop column dispensed_1',
|
||||||
db.dropColumn('cash_out_txs', 'dispensed_2'),
|
'alter table cash_out_txs drop column dispensed_2',
|
||||||
db.dropColumn('cash_out_txs', 'rejected_1'),
|
'alter table cash_out_txs drop column rejected_1',
|
||||||
db.dropColumn('cash_out_txs', 'rejected_2'),
|
'alter table cash_out_txs drop column rejected_2',
|
||||||
db.dropColumn('cash_out_txs', 'denomination_1'),
|
'alter table cash_out_txs drop column denomination_1',
|
||||||
db.dropColumn('cash_out_txs', 'denomination_2'),
|
'alter table cash_out_txs drop column denomination_2',
|
||||||
db.dropColumn('cash_out_txs', 'dispense_error'),
|
'alter table cash_out_txs drop column dispense_error',
|
||||||
db.dropColumn('cash_out_txs', 'dispense_time'),
|
'alter table cash_out_txs drop column dispense_time',
|
||||||
db.addColumn('cash_out_txs', 'dispense_confirmed', 'boolean default false'),
|
'alter table cash_out_txs add column dispense_confirmed boolean default false',
|
||||||
db.renameColumn('cash_out_txs', 'dispensed', 'dispense')
|
'alter table cash_out_txs rename column dispensed to dispense'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.addColumn('user_config', 'valid', 'boolean not null')
|
'alter table user_config add column valid boolean not null'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.addColumn('cash_out_txs', 'provisioned_1', 'integer'),
|
'alter table cash_out_txs add column provisioned_1 integer',
|
||||||
db.addColumn('cash_out_txs', 'provisioned_2', 'integer'),
|
'alter table cash_out_txs add column provisioned_2 integer',
|
||||||
db.addColumn('cash_out_txs', 'denomination_1', 'integer'),
|
'alter table cash_out_txs add column denomination_1 integer',
|
||||||
db.addColumn('cash_out_txs', 'denomination_2', 'integer')
|
'alter table cash_out_txs add column denomination_2 integer'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ const db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const sql = [
|
const sql = [
|
||||||
db.dropColumn('devices', 'name')
|
'alter table devices drop column name'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,24 +2,24 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
`create table if not exists machine_pings (
|
`create table machine_pings (
|
||||||
id uuid PRIMARY KEY,
|
id uuid PRIMARY KEY,
|
||||||
device_id text not null,
|
device_id text not null,
|
||||||
serial_number integer not null,
|
serial_number integer not null,
|
||||||
device_time timestamptz not null,
|
device_time timestamptz not null,
|
||||||
created timestamptz not null default now())`,
|
created timestamptz not null default now())`,
|
||||||
`create table if not exists aggregated_machine_pings (
|
`create table aggregated_machine_pings (
|
||||||
id uuid PRIMARY KEY,
|
id uuid PRIMARY KEY,
|
||||||
device_id text not null,
|
device_id text not null,
|
||||||
dropped_pings integer not null,
|
dropped_pings integer not null,
|
||||||
total_pings integer not null,
|
total_pings integer not null,
|
||||||
lag_sd_ms integer not null,
|
lag_sd_ms integer not null,
|
||||||
lag_min_ms integer not null,
|
lag_min_ms integer not null,
|
||||||
lag_max_ms integer not null,
|
lag_max_ms integer not null,
|
||||||
lag_median_ms integer not null,
|
lag_median_ms integer not null,
|
||||||
day date not null)`,
|
day date not null)`,
|
||||||
db.dropColumn('machine_events', 'device_time'),
|
'alter table machine_events drop column device_time',
|
||||||
db.addColumn('machine_events', 'device_time', 'timestamptz')
|
'alter table machine_events add column device_time timestamptz'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.addColumn('cash_in_txs', 'cash_in_fee', 'numeric(14, 5) not null'),
|
'alter table cash_in_txs add column cash_in_fee numeric(14, 5) not null',
|
||||||
db.addColumn('cash_in_txs', 'cash_in_fee_crypto', 'bigint not null'),
|
'alter table cash_in_txs add column cash_in_fee_crypto bigint not null',
|
||||||
db.addColumn('cash_in_txs', 'minimum_tx', 'integer not null'),
|
'alter table cash_in_txs add column minimum_tx integer not null',
|
||||||
db.addColumn('bills', 'cash_in_fee', 'numeric(14, 5) not null'),
|
'alter table bills add column cash_in_fee numeric(14, 5) not null',
|
||||||
db.addColumn('bills', 'cash_in_fee_crypto', 'bigint not null'),
|
'alter table bills add column cash_in_fee_crypto bigint not null',
|
||||||
db.addColumn('bills', 'crypto_atoms_after_fee', 'bigint not null')
|
'alter table bills add column crypto_atoms_after_fee bigint not null'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.addColumn('cash_out_txs', 'error_code', 'text')
|
'alter table cash_out_txs add column error_code text'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,21 +2,21 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
`create table if not exists cash_out_refills (
|
`create table cash_out_refills (
|
||||||
id uuid PRIMARY KEY,
|
id uuid PRIMARY KEY,
|
||||||
device_id text not null,
|
device_id text not null,
|
||||||
user_id integer not null,
|
user_id integer not null,
|
||||||
cassette1 integer not null,
|
cassette1 integer not null,
|
||||||
cassette2 integer not null,
|
cassette2 integer not null,
|
||||||
denomination1 integer not null,
|
denomination1 integer not null,
|
||||||
denomination2 integer not null,
|
denomination2 integer not null,
|
||||||
created timestamptz not null default now())`,
|
created timestamptz not null default now())`,
|
||||||
`create table if not exists cash_in_refills (
|
`create table cash_in_refills (
|
||||||
id uuid PRIMARY KEY,
|
id uuid PRIMARY KEY,
|
||||||
device_id text not null,
|
device_id text not null,
|
||||||
user_id integer not null,
|
user_id integer not null,
|
||||||
cash_box_count integer not null,
|
cash_box_count integer not null,
|
||||||
created timestamptz not null default now())`
|
created timestamptz not null default now())`
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,26 +3,26 @@ var anonymous = require('../lib/constants').anonymousCustomer
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const sql =
|
const sql =
|
||||||
[`create table if not exists customers (
|
[`create table customers (
|
||||||
id uuid PRIMARY KEY,
|
id uuid PRIMARY KEY,
|
||||||
phone text unique,
|
phone text unique,
|
||||||
phone_at timestamptz,
|
phone_at timestamptz,
|
||||||
id_card_number text,
|
id_card_number text,
|
||||||
id_card_expiration date,
|
id_card_expiration date,
|
||||||
id_card_data json,
|
id_card_data json,
|
||||||
id_card_at timestamptz,
|
id_card_at timestamptz,
|
||||||
name text,
|
name text,
|
||||||
address text,
|
address text,
|
||||||
manually_verified boolean,
|
manually_verified boolean,
|
||||||
sanctions_check boolean,
|
sanctions_check boolean,
|
||||||
front_facing_cam_path text,
|
front_facing_cam_path text,
|
||||||
front_facing_cam_at timestamptz,
|
front_facing_cam_at timestamptz,
|
||||||
id_card_image_path text,
|
id_card_image_path text,
|
||||||
id_card_image_at timestamptz,
|
id_card_image_at timestamptz,
|
||||||
created timestamptz NOT NULL DEFAULT now() )`,
|
created timestamptz NOT NULL DEFAULT now() )`,
|
||||||
`insert into customers (id, name) VALUES ('${anonymous.uuid}','${anonymous.name}') ON CONFLICT DO NOTHING`,
|
`insert into customers (id, name) VALUES ( '${anonymous.uuid}','${anonymous.name}' )`,
|
||||||
db.addColumn('cash_in_txs', 'customer_id', `uuid references customers (id) DEFAULT '${anonymous.uuid}'`),
|
`alter table cash_in_txs add column customer_id uuid references customers (id) DEFAULT '${anonymous.uuid}'`,
|
||||||
db.addColumn('cash_out_txs', 'customer_id', `uuid references customers (id) DEFAULT '${anonymous.uuid}'`)
|
`alter table cash_out_txs add column customer_id uuid references customers (id) DEFAULT '${anonymous.uuid}'`
|
||||||
]
|
]
|
||||||
|
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
var db = require('./db')
|
var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const sql = [
|
const sql =
|
||||||
db.defineEnum('compliance_types', "'manual', 'sanctions', 'sanctions_override'"),
|
[ "create type compliance_types as enum ('manual', 'sanctions', 'sanctions_override')",
|
||||||
`create table if not exists compliance_authorizations (
|
`create table compliance_authorizations (
|
||||||
id uuid PRIMARY KEY,
|
id uuid PRIMARY KEY,
|
||||||
customer_id uuid REFERENCES customers (id),
|
customer_id uuid REFERENCES customers (id),
|
||||||
compliance_type compliance_types NOT NULL,
|
compliance_type compliance_types NOT NULL,
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const sql = [
|
const sql = [
|
||||||
db.dropColumn('cash_in_txs', 'device_time'),
|
'alter table cash_in_txs drop column device_time',
|
||||||
db.dropColumn('cash_out_txs', 'device_time')
|
'alter table cash_out_txs drop column device_time'
|
||||||
]
|
]
|
||||||
|
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const sql = [
|
const sql = [
|
||||||
db.addColumn('cash_in_txs', 'tx_version', 'integer not null'),
|
'alter table cash_in_txs add column tx_version integer not null',
|
||||||
db.addColumn('cash_out_txs', 'tx_version', 'integer not null')
|
'alter table cash_out_txs add column tx_version integer not null'
|
||||||
]
|
]
|
||||||
|
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const sql = [
|
const sql = [
|
||||||
db.addColumn('cash_out_txs', 'published_at', 'timestamptz'),
|
'alter table cash_out_txs add column published_at timestamptz',
|
||||||
db.renameColumn('cash_out_txs', 'confirmation_time', 'confirmed_at')
|
'alter table cash_out_txs rename column confirmation_time to confirmed_at'
|
||||||
]
|
]
|
||||||
|
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
|
|
|
||||||
|
|
@ -12,38 +12,39 @@ exports.up = function (next) {
|
||||||
*
|
*
|
||||||
* @see {@link http://blog.yo1.dog/updating-enum-values-in-postgresql-the-safe-and-easy-way/}
|
* @see {@link http://blog.yo1.dog/updating-enum-values-in-postgresql-the-safe-and-easy-way/}
|
||||||
*/
|
*/
|
||||||
db.defineEnum('compliance_type', "'authorized', 'sms', 'id_card_data', 'id_card_photo', 'sanctions_check', 'front_facing_cam', 'hard_limit'"),
|
`create type compliance_type as enum
|
||||||
db.alterColumn('compliance_authorizations', 'compliance_type', 'set data type compliance_type using compliance_type::text::compliance_type'),
|
('authorized', 'sms', 'id_card_data', 'id_card_photo', 'sanctions_check', 'front_facing_cam', 'hard_limit')`,
|
||||||
db.dropEnum('compliance_types'),
|
'alter table compliance_authorizations alter column compliance_type set data type compliance_type using compliance_type::text::compliance_type',
|
||||||
|
'drop type compliance_types',
|
||||||
|
|
||||||
db.defineEnum('verification_type', "'verified', 'blocked', 'automatic'"),
|
"create type verification_type as enum ('verified', 'blocked', 'automatic')",
|
||||||
|
|
||||||
db.dropColumn('customers', 'manually_verified'),
|
'alter table customers drop column manually_verified ',
|
||||||
db.addColumn('customers', 'sms_override', 'verification_type not null default \'automatic\''),
|
"alter table customers add column sms_override verification_type not null default 'automatic'",
|
||||||
db.addColumn('customers', 'sms_override_by', 'text references user_tokens (token)'),
|
'alter table customers add column sms_override_by text references user_tokens (token)',
|
||||||
db.addColumn('customers', 'sms_override_at', 'timestamptz'),
|
'alter table customers add column sms_override_at timestamptz',
|
||||||
db.addColumn('customers', 'id_card_data_override', 'verification_type not null default \'automatic\''),
|
"alter table customers add column id_card_data_override verification_type not null default 'automatic'",
|
||||||
db.addColumn('customers', 'id_card_data_override_by', 'text references user_tokens (token)'),
|
'alter table customers add column id_card_data_override_by text references user_tokens (token)',
|
||||||
db.addColumn('customers', 'id_card_data_override_at', 'timestamptz'),
|
'alter table customers add column id_card_data_override_at timestamptz',
|
||||||
db.addColumn('customers', 'id_card_photo_override', 'verification_type not null default \'automatic\''),
|
"alter table customers add column id_card_photo_override verification_type not null default 'automatic'",
|
||||||
db.addColumn('customers', 'id_card_photo_override_by', 'text references user_tokens (token)'),
|
'alter table customers add column id_card_photo_override_by text references user_tokens (token)',
|
||||||
db.addColumn('customers', 'id_card_photo_override_at', 'timestamptz'),
|
'alter table customers add column id_card_photo_override_at timestamptz',
|
||||||
db.addColumn('customers', 'front_facing_cam_override', 'verification_type not null default \'automatic\''),
|
"alter table customers add column front_facing_cam_override verification_type not null default 'automatic'",
|
||||||
db.addColumn('customers', 'front_facing_cam_override_by', 'text references user_tokens (token)'),
|
'alter table customers add column front_facing_cam_override_by text references user_tokens (token)',
|
||||||
db.addColumn('customers', 'front_facing_cam_override_at', 'timestamptz'),
|
'alter table customers add column front_facing_cam_override_at timestamptz',
|
||||||
db.addColumn('customers', 'sanctions_check_override', 'verification_type not null default \'automatic\''),
|
"alter table customers add column sanctions_check_override verification_type not null default 'automatic'",
|
||||||
db.addColumn('customers', 'sanctions_check_override_by', 'text references user_tokens (token)'),
|
'alter table customers add column sanctions_check_override_by text references user_tokens (token)',
|
||||||
db.addColumn('customers', 'sanctions_check_override_at', 'timestamptz'),
|
'alter table customers add column sanctions_check_override_at timestamptz',
|
||||||
db.addColumn('customers', 'authorized_override', 'verification_type not null default \'automatic\''),
|
"alter table customers add column authorized_override verification_type not null default 'automatic'",
|
||||||
db.addColumn('customers', 'authorized_override_by', 'text references user_tokens (token)'),
|
'alter table customers add column authorized_override_by text references user_tokens (token)',
|
||||||
db.addColumn('customers', 'authorized_override_at', 'timestamptz'),
|
'alter table customers add column authorized_override_at timestamptz',
|
||||||
db.addColumn('customers', 'authorized_at', 'timestamptz'),
|
'alter table customers add column authorized_at timestamptz',
|
||||||
db.addColumn('customers', 'sanctions_check_at', 'timestamptz'),
|
'alter table customers add column sanctions_check_at timestamptz',
|
||||||
|
|
||||||
'alter table compliance_authorizations rename to compliance_overrides',
|
'alter table compliance_authorizations rename to compliance_overrides',
|
||||||
db.addColumn('compliance_overrides', 'verification', 'verification_type not null'),
|
'alter table compliance_overrides add column verification verification_type not null',
|
||||||
db.renameColumn('compliance_overrides', 'authorized_at', 'override_at'),
|
'alter table compliance_overrides rename column authorized_at to override_at',
|
||||||
db.renameColumn('compliance_overrides', 'authorized_by', 'override_by')
|
'alter table compliance_overrides rename column authorized_by to override_by'
|
||||||
]
|
]
|
||||||
|
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
|
|
|
||||||
|
|
@ -4,21 +4,21 @@ const db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const sql = [
|
const sql = [
|
||||||
db.renameColumn('customers', 'id_card_number', 'id_card_data_number'),
|
'alter table customers rename column id_card_number to id_card_data_number',
|
||||||
db.renameColumn('customers', 'id_card_at', 'id_card_data_at'),
|
'alter table customers rename column id_card_at to id_card_data_at',
|
||||||
db.renameColumn('customers', 'sanctions_check', 'sanctions'),
|
'alter table customers rename column sanctions_check to sanctions',
|
||||||
db.renameColumn('customers', 'sanctions_check_at', 'sanctions_at'),
|
'alter table customers rename column sanctions_check_at to sanctions_at',
|
||||||
db.renameColumn('customers', 'front_facing_cam_at', 'front_camera_at'),
|
'alter table customers rename column front_facing_cam_at to front_camera_at',
|
||||||
db.renameColumn('customers', 'front_facing_cam_path', 'front_camera_path'),
|
'alter table customers rename column front_facing_cam_path to front_camera_path',
|
||||||
db.renameColumn('customers', 'id_card_image_path', 'id_card_photo_path'),
|
'alter table customers rename column id_card_image_path to id_card_photo_path',
|
||||||
db.renameColumn('customers', 'id_card_image_at', 'id_card_photo_at'),
|
'alter table customers rename column id_card_image_at to id_card_photo_at',
|
||||||
db.renameColumn('customers', 'id_card_expiration', 'id_card_data_expiration'),
|
'alter table customers rename column id_card_expiration to id_card_data_expiration',
|
||||||
db.renameColumn('customers', 'front_facing_cam_override', 'front_camera_override'),
|
'alter table customers rename column front_facing_cam_override to front_camera_override',
|
||||||
db.renameColumn('customers', 'front_facing_cam_override_by', 'front_camera_override_by'),
|
'alter table customers rename column front_facing_cam_override_by to front_camera_override_by',
|
||||||
db.renameColumn('customers', 'front_facing_cam_override_at', 'front_camera_override_at'),
|
'alter table customers rename column front_facing_cam_override_at to front_camera_override_at',
|
||||||
db.renameColumn('customers', 'sanctions_check_override', 'sanctions_override'),
|
'alter table customers rename column sanctions_check_override to sanctions_override',
|
||||||
db.renameColumn('customers', 'sanctions_check_override_by', 'sanctions_override_by'),
|
'alter table customers rename column sanctions_check_override_by to sanctions_override_by',
|
||||||
db.renameColumn('customers', 'sanctions_check_override_at', 'sanctions_override_at'),
|
'alter table customers rename column sanctions_check_override_at to sanctions_override_at',
|
||||||
/**
|
/**
|
||||||
* Replace all compliance_type enum values
|
* Replace all compliance_type enum values
|
||||||
*
|
*
|
||||||
|
|
@ -27,10 +27,11 @@ exports.up = function (next) {
|
||||||
*
|
*
|
||||||
* @see {@link http://blog.yo1.dog/updating-enum-values-in-postgresql-the-safe-and-easy-way/}
|
* @see {@link http://blog.yo1.dog/updating-enum-values-in-postgresql-the-safe-and-easy-way/}
|
||||||
*/
|
*/
|
||||||
db.renameEnum('compliance_type', 'old_compliance_type'),
|
'alter type compliance_type rename to old_compliance_type',
|
||||||
db.defineEnum('compliance_type', "'authorized', 'sms', 'id_card_data', 'id_card_photo', 'sanctions', 'front_camera', 'hard_limit'"),
|
`create type compliance_type as enum
|
||||||
db.alterColumn('compliance_overrides', 'compliance_type', 'set data type compliance_type using compliance_type::text::compliance_type'),
|
('authorized', 'sms', 'id_card_data', 'id_card_photo', 'sanctions', 'front_camera', 'hard_limit')`,
|
||||||
db.dropEnum('old_compliance_type')
|
'alter table compliance_overrides alter column compliance_type set data type compliance_type using compliance_type::text::compliance_type',
|
||||||
|
'drop type old_compliance_type'
|
||||||
]
|
]
|
||||||
|
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const sql =
|
const sql =
|
||||||
[`create table if not exists logs (
|
[`create table logs (
|
||||||
id uuid PRIMARY KEY,
|
id uuid PRIMARY KEY,
|
||||||
device_id text,
|
device_id text,
|
||||||
log_level text,
|
log_level text,
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,11 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const sql =
|
const sql =
|
||||||
[`create table if not exists support_logs (
|
[`create table support_logs (
|
||||||
id uuid PRIMARY KEY,
|
id uuid PRIMARY KEY,
|
||||||
device_id text,
|
device_id text,
|
||||||
timestamp timestamptz not null default now() )`,
|
timestamp timestamptz not null default now() )`,
|
||||||
db.addColumn('logs', 'server_timestamp', 'timestamptz not null default now()')
|
'alter table logs add column server_timestamp timestamptz not null default now() '
|
||||||
]
|
]
|
||||||
|
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,17 @@ exports.up = function (next) {
|
||||||
return migrateTools.migrateNames()
|
return migrateTools.migrateNames()
|
||||||
.then(updateSql => {
|
.then(updateSql => {
|
||||||
const sql = [
|
const sql = [
|
||||||
db.addColumn('devices', 'name', 'text'),
|
'alter table devices add column name text',
|
||||||
updateSql,
|
updateSql,
|
||||||
db.alterColumn('devices', 'name', 'set not null')
|
'alter table devices alter column name set not null'
|
||||||
]
|
]
|
||||||
|
|
||||||
return db.multi(sql, next)
|
return db.multi(sql, next)
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
const sql = [
|
const sql = [
|
||||||
db.addColumn('devices', 'name', 'text'),
|
'alter table devices add column name text',
|
||||||
db.alterColumn('devices', 'name', 'set not null')
|
'alter table devices alter column name set not null'
|
||||||
]
|
]
|
||||||
|
|
||||||
return db.multi(sql, next)
|
return db.multi(sql, next)
|
||||||
|
|
@ -23,8 +23,6 @@ exports.up = function (next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.down = function (next) {
|
exports.down = function (next) {
|
||||||
const sql = [
|
const sql = ['alter table devices drop column name']
|
||||||
db.dropColumn('devices', 'name')
|
|
||||||
]
|
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
const db = require('./db')
|
const db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const sql = [
|
const sql = ['alter table logs add column serial integer not null default 0']
|
||||||
db.addColumn('logs', 'serial', 'integer not null default 0')
|
|
||||||
]
|
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const sql =
|
const sql =
|
||||||
[`create table if not exists sanctions_logs (
|
[`create table sanctions_logs (
|
||||||
id uuid PRIMARY KEY,
|
id uuid PRIMARY KEY,
|
||||||
device_id text not null,
|
device_id text not null,
|
||||||
sanctioned_id text not null,
|
sanctioned_id text not null,
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.alterColumn('cash_in_txs', 'cash_in_fee_crypto', 'type numeric(30)'),
|
'alter table cash_in_txs alter column cash_in_fee_crypto type numeric(30)',
|
||||||
db.alterColumn('cash_in_txs', 'crypto_atoms', 'type numeric(30)'),
|
'alter table cash_in_txs alter column crypto_atoms type numeric(30)',
|
||||||
db.alterColumn('cash_out_txs', 'crypto_atoms', 'type numeric(30)'),
|
'alter table cash_out_txs alter column crypto_atoms type numeric(30)',
|
||||||
db.alterColumn('trades', 'crypto_atoms', 'type numeric(30)'),
|
'alter table trades alter column crypto_atoms type numeric(30)',
|
||||||
db.alterColumn('bills', 'crypto_atoms', 'type numeric(30)'),
|
'alter table bills alter column crypto_atoms type numeric(30)',
|
||||||
db.alterColumn('bills', 'cash_in_fee_crypto', 'type numeric(30)'),
|
'alter table bills alter column cash_in_fee_crypto type numeric(30)',
|
||||||
db.alterColumn('bills', 'crypto_atoms_after_fee', 'type numeric(30)')
|
'alter table bills alter column crypto_atoms_after_fee type numeric(30)'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.addColumn('devices', 'last_online', 'timestamptz not null default now()'),
|
'alter table devices add column last_online timestamptz not null default now()',
|
||||||
db.addColumn('devices', 'location', 'json not null default \'{}\'')
|
"alter table devices add column location json not null default '{}'"
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
const sql = [
|
const sql = [
|
||||||
db.addColumn('cash_in_txs', 'terms_accepted', 'boolean not null default false'),
|
'alter table cash_in_txs add column terms_accepted boolean not null default false',
|
||||||
db.addColumn('cash_out_txs', 'terms_accepted', 'boolean not null default false')
|
'alter table cash_out_txs add column terms_accepted boolean not null default false'
|
||||||
]
|
]
|
||||||
|
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.addColumn('cash_out_txs', 'layer_2_address', 'text null'),
|
'alter table cash_out_txs add column layer_2_address text null',
|
||||||
db.addColumn('cash_out_actions', 'layer_2_address', 'text null')
|
'alter table cash_out_actions add column layer_2_address text null'
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ var db = require('./db')
|
||||||
|
|
||||||
exports.up = function (next) {
|
exports.up = function (next) {
|
||||||
var sql = [
|
var sql = [
|
||||||
db.addColumn('cash_out_actions', 'device_id', 'text not null default \'\'')
|
"alter table cash_out_actions add device_id text not null default ''"
|
||||||
]
|
]
|
||||||
db.multi(sql, next)
|
db.multi(sql, next)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
153
migrations/db.js
153
migrations/db.js
|
|
@ -1,22 +1,7 @@
|
||||||
const _ = require('lodash/fp')
|
|
||||||
const db = require('../lib/db')
|
const db = require('../lib/db')
|
||||||
const sequential = require('promise-sequential')
|
const sequential = require('promise-sequential')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {multi}
|
||||||
multi,
|
|
||||||
defineEnum,
|
|
||||||
dropEnum,
|
|
||||||
renameEnum,
|
|
||||||
alterColumn,
|
|
||||||
addColumn,
|
|
||||||
dropColumn,
|
|
||||||
renameColumn,
|
|
||||||
dropConstraint,
|
|
||||||
addConstraint,
|
|
||||||
addSequence,
|
|
||||||
alterSequence,
|
|
||||||
ifColumn
|
|
||||||
}
|
|
||||||
|
|
||||||
function multi (sqls, cb) {
|
function multi (sqls, cb) {
|
||||||
const doQuery = s => {
|
const doQuery = s => {
|
||||||
|
|
@ -36,139 +21,3 @@ function multi (sqls, cb) {
|
||||||
cb(err)
|
cb(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function beginEnd (statement) {
|
|
||||||
return `
|
|
||||||
DO $$
|
|
||||||
BEGIN
|
|
||||||
${statement};
|
|
||||||
END $$
|
|
||||||
`
|
|
||||||
}
|
|
||||||
|
|
||||||
function defineEnum (name, values) {
|
|
||||||
return beginEnd(`
|
|
||||||
IF NOT EXISTS (
|
|
||||||
SELECT 1 FROM pg_type WHERE typname = '${name}'
|
|
||||||
) THEN
|
|
||||||
CREATE TYPE ${name} AS ENUM (${values});
|
|
||||||
END IF
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
function dropEnum (name) {
|
|
||||||
return beginEnd(`
|
|
||||||
IF EXISTS (
|
|
||||||
SELECT 1 FROM pg_type WHERE typname = '${name}'
|
|
||||||
) THEN
|
|
||||||
DROP TYPE ${name};
|
|
||||||
END IF
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
function renameEnum (name, newName) {
|
|
||||||
return beginEnd(`
|
|
||||||
IF EXISTS (
|
|
||||||
SELECT 1 FROM pg_type WHERE typname = '${name}'
|
|
||||||
) THEN
|
|
||||||
IF NOT EXISTS (
|
|
||||||
SELECT 1 FROM pg_type WHERE typname = '${newName}'
|
|
||||||
) THEN
|
|
||||||
ALTER TYPE ${name} RENAME TO ${newName};
|
|
||||||
END IF;
|
|
||||||
END IF
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
function ifColumn (table, column, statement, not, skipBeginEnd) {
|
|
||||||
statement = `
|
|
||||||
IF EXISTS (
|
|
||||||
SELECT NULL
|
|
||||||
FROM INFORMATION_SCHEMA.TABLEs
|
|
||||||
WHERE table_name = '${table}'
|
|
||||||
) THEN
|
|
||||||
IF ${not ? 'NOT' : ''} EXISTS (
|
|
||||||
SELECT NULL
|
|
||||||
FROM INFORMATION_SCHEMA.COLUMNS
|
|
||||||
WHERE table_name = '${table}'
|
|
||||||
AND column_name = '${column}'
|
|
||||||
) THEN
|
|
||||||
${statement};
|
|
||||||
END IF;
|
|
||||||
END IF
|
|
||||||
`
|
|
||||||
return skipBeginEnd ? statement : beginEnd(statement)
|
|
||||||
}
|
|
||||||
|
|
||||||
function alterColumn (table, column, change) {
|
|
||||||
return ifColumn(table, column, `
|
|
||||||
ALTER TABLE ${table}
|
|
||||||
ALTER ${column} ${change}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
function addColumn (table, column, change) {
|
|
||||||
return ifColumn(table, column, `
|
|
||||||
ALTER TABLE ${table}
|
|
||||||
ADD ${column} ${change}`, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
function dropColumn (table, column) {
|
|
||||||
return ifColumn(table, column, `
|
|
||||||
ALTER TABLE ${table}
|
|
||||||
DROP ${column}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
function renameColumn (table, column, newName) {
|
|
||||||
return ifColumn(table, column,
|
|
||||||
ifColumn(table, newName, `
|
|
||||||
ALTER TABLE ${table}
|
|
||||||
RENAME ${column} to ${newName}`, true, true))
|
|
||||||
}
|
|
||||||
|
|
||||||
function dropConstraint (table, column) {
|
|
||||||
return beginEnd(`
|
|
||||||
IF EXISTS(
|
|
||||||
SELECT NULL
|
|
||||||
FROM INFORMATION_SCHEMA.constraint_column_usage
|
|
||||||
WHERE constraint_name = '${column}'
|
|
||||||
) THEN
|
|
||||||
ALTER TABLE ${table} DROP CONSTRAINT ${column};
|
|
||||||
END IF
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
function addConstraint (table, column, change, refTable, refColumn) {
|
|
||||||
return ifColumn(refTable, refColumn, `
|
|
||||||
IF NOT EXISTS(
|
|
||||||
SELECT NULL
|
|
||||||
FROM INFORMATION_SCHEMA.constraint_column_usage
|
|
||||||
WHERE constraint_name = '${column}'
|
|
||||||
) THEN
|
|
||||||
ALTER TABLE ${table} ADD CONSTRAINT ${column} ${change};
|
|
||||||
END IF
|
|
||||||
`, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
function addSequence (name, change) {
|
|
||||||
return beginEnd(`
|
|
||||||
IF NOT EXISTS(
|
|
||||||
SELECT NULL
|
|
||||||
FROM INFORMATION_SCHEMA.sequences
|
|
||||||
WHERE sequence_name = '${name}'
|
|
||||||
) THEN
|
|
||||||
CREATE SEQUENCE ${name} ${change};
|
|
||||||
END IF
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
function alterSequence (name, change) {
|
|
||||||
return beginEnd(`
|
|
||||||
IF EXISTS(
|
|
||||||
SELECT NULL
|
|
||||||
FROM INFORMATION_SCHEMA.sequences
|
|
||||||
WHERE sequence_name = '${name}'
|
|
||||||
) THEN
|
|
||||||
ALTER SEQUENCE ${name} ${change};
|
|
||||||
END IF
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
|
||||||
1171
package-lock.json
generated
1171
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -37,7 +37,7 @@
|
||||||
"mailgun-js": "^0.21.0",
|
"mailgun-js": "^0.21.0",
|
||||||
"make-dir": "^1.0.0",
|
"make-dir": "^1.0.0",
|
||||||
"mem": "^1.1.0",
|
"mem": "^1.1.0",
|
||||||
"migrate": "^0.2.2",
|
"migrate": "^1.6.2",
|
||||||
"minimist": "^1.2.0",
|
"minimist": "^1.2.0",
|
||||||
"moment": "^2.17.0",
|
"moment": "^2.17.0",
|
||||||
"morgan": "^1.8.2",
|
"morgan": "^1.8.2",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue