Merge branch 'dev' into feat/lam-1291/stress-testing

* dev: (85 commits)
  chore: console.log debug leftovers
  fix: third level navigation links
  fix: show subheader on refresh
  fix: machines/:id routing
  fix: customer route
  chore: update wallet nodes
  feat: shorten long addresses in funding page
  feat: shorten long addresses
  refactor: support copied text different from presented text
  chore: udpate react, downshift and routing
  refactor: use Wizard component on first route
  fix: autocomplete component rendering
  feat: skip2fa option on .env
  fix: drop contraint before dropping index
  chore: stop using alias imports
  fix: re-instate urlResolver
  chore: server code formatting
  chore: reformat code
  chore: adding eslint and prettier config
  chore: typo
  ...
This commit is contained in:
siiky 2025-05-20 11:57:32 +01:00
commit e10493abc6
1398 changed files with 60329 additions and 157527 deletions

View file

@ -0,0 +1,38 @@
const db = require('./db')
exports.up = function (next) {
var sqls = [
'CREATE TABLE IF NOT EXISTS user_config ( ' +
'id serial PRIMARY KEY, ' +
'type text NOT NULL, ' +
'data json NOT NULL ' +
')',
'CREATE TABLE IF NOT EXISTS devices ( ' +
'id serial PRIMARY KEY, ' +
'fingerprint text NOT NULL UNIQUE, ' +
'name text, ' +
'authorized boolean, ' +
'unpair boolean NOT NULL DEFAULT false' +
')',
'CREATE TABLE IF NOT EXISTS pairing_tokens (' +
'id serial PRIMARY KEY, ' +
'token text, ' +
'created timestamp NOT NULL DEFAULT now() ' +
')',
'CREATE TABLE IF NOT EXISTS users ( ' +
'id serial PRIMARY KEY, ' +
'userName text NOT NULL UNIQUE, ' +
'salt text NOT NULL, ' +
'pwdHash text NOT NULL ' +
')',
]
db.multi(sqls, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,22 @@
var db = require('./db')
exports.up = function (next) {
const sql = [
'CREATE TABLE bills ( ' +
'id uuid PRIMARY KEY, ' +
'device_fingerprint text NOT NULL, ' +
'denomination integer NOT NULL, ' +
'currency_code text NOT NULL, ' +
'satoshis integer NOT NULL, ' +
'to_address text NOT NULL, ' +
'session_id uuid NOT NULL, ' +
'device_time bigint NOT NULL, ' +
'created timestamp NOT NULL DEFAULT now() )',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,20 @@
var db = require('./db')
exports.up = function (next) {
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,
)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,88 @@
var db = require('./db')
function singleQuotify(item) {
return "'" + item + "'"
}
exports.up = function (next) {
var stages = [
'initial_request',
'partial_request',
'final_request',
'partial_send',
'deposit',
'dispense_request',
'dispense',
]
.map(singleQuotify)
.join(',')
var authorizations = [
'timeout',
'machine',
'pending',
'rejected',
'published',
'authorized',
'confirmed',
]
.map(singleQuotify)
.join(',')
var sqls = [
'CREATE TYPE transaction_stage AS ENUM (' + stages + ')',
'CREATE TYPE transaction_authority AS ENUM (' + authorizations + ')',
'CREATE TABLE transactions ( ' +
'id serial PRIMARY KEY, ' +
'session_id uuid NOT NULL, ' +
'device_fingerprint text, ' +
'to_address text NOT NULL, ' +
'satoshis integer NOT NULL DEFAULT 0, ' +
'fiat integer NOT NULL DEFAULT 0, ' +
'currency_code text NOT NULL, ' +
'fee integer NOT NULL DEFAULT 0, ' +
'incoming boolean NOT NULL, ' +
'stage transaction_stage NOT NULL, ' +
'authority transaction_authority NOT NULL, ' +
'tx_hash text, ' +
'error text, ' +
'created timestamp NOT NULL DEFAULT now(), ' +
'UNIQUE (session_id, to_address, stage, authority) ' +
')',
'CREATE INDEX ON transactions (session_id)',
'CREATE TABLE pending_transactions ( ' +
'id serial PRIMARY KEY, ' +
'device_fingerprint text NOT NULL, ' +
'session_id uuid UNIQUE NOT NULL, ' +
'incoming boolean NOT NULL, ' +
'currency_code text NOT NULL, ' +
'to_address text NOT NULL, ' +
'satoshis integer NOT NULL, ' +
'updated timestamp NOT NULL DEFAULT now() ' +
')',
'CREATE TABLE dispenses ( ' +
'id serial PRIMARY KEY, ' +
'device_fingerprint text NOT NULL, ' +
'transaction_id integer UNIQUE REFERENCES transactions(id), ' +
'dispense1 integer NOT NULL, ' +
'reject1 integer NOT NULL, ' +
'count1 integer NOT NULL, ' +
'dispense2 integer NOT NULL, ' +
'reject2 integer NOT NULL, ' +
'count2 integer NOT NULL, ' +
'refill boolean NOT NULL, ' +
'error text, ' +
'created timestamp NOT NULL DEFAULT now() ' +
')',
'CREATE INDEX ON dispenses (device_fingerprint)',
]
db.multi(sqls, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,18 @@
var db = require('./db')
exports.up = function (next) {
var sqls = [
'alter table transactions alter satoshis TYPE bigint',
"alter table transactions add crypto_code text default 'BTC'",
"alter table pending_transactions add crypto_code text default 'BTC'",
'alter table pending_transactions alter satoshis TYPE bigint',
"alter table bills add crypto_code text default 'BTC'",
'alter table bills alter satoshis TYPE bigint',
]
db.multi(sqls, next)
}
exports.down = function (next) {
next()
}

View file

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

View file

@ -0,0 +1,13 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'alter table transactions add phone text',
'create index on transactions (phone)',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,33 @@
var db = require('./db')
function singleQuotify(item) {
return "'" + item + "'"
}
exports.up = function (next) {
var statuses = [
'notSeen',
'published',
'authorized',
'instant',
'confirmed',
'rejected',
'insufficientFunds',
]
.map(singleQuotify)
.join(',')
var sql = [
'create type status_stage AS enum (' + statuses + ')',
'alter table transactions add dispensed boolean NOT NULL DEFAULT false',
'alter table transactions add notified boolean NOT NULL DEFAULT false',
'alter table transactions add redeem boolean NOT NULL DEFAULT false',
'alter table transactions add confirmation_time timestamptz',
"alter table transactions add status status_stage NOT NULL DEFAULT 'notSeen'",
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,17 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'alter table transactions alter created type timestamptz',
'alter table bills alter created type timestamptz',
'alter table dispenses alter created type timestamptz',
'alter table machine_events alter created type timestamptz',
'alter table pairing_tokens alter created type timestamptz',
'alter table pending_transactions alter updated type timestamptz',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

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

View file

@ -0,0 +1,72 @@
var db = require('./db')
function singleQuotify(item) {
return "'" + item + "'"
}
exports.up = function (next) {
var actions = [
'published',
'authorized',
'instant',
'confirmed',
'rejected',
'insufficientFunds',
'dispenseRequested',
'dispensed',
'notified',
'addedPhone',
'redeem',
]
.map(singleQuotify)
.join(',')
var sql = [
`create table cash_in_txs (
session_id uuid PRIMARY KEY,
device_fingerprint text NOT NULL,
to_address text NOT NULL,
crypto_atoms bigint NOT NULL,
crypto_code text NOT NULL,
fiat numeric(14, 5) NOT NULL,
currency_code text NOT NULL,
fee bigint,
tx_hash text,
phone text,
error text,
created timestamptz NOT NULL default now()
)`,
`create table cash_out_txs (
session_id uuid PRIMARY KEY,
device_fingerprint text NOT NULL,
to_address text NOT NULL,
crypto_atoms bigint NOT NULL,
crypto_code text NOT NULL,
fiat numeric(14, 5) NOT NULL,
currency_code text NOT NULL,
tx_hash text,
status status_stage NOT NULL default 'notSeen',
dispensed boolean NOT NULL default false,
notified boolean NOT NULL default false,
redeem boolean NOT NULL default false,
phone text,
error text,
created timestamptz NOT NULL default now(),
confirmation_time timestamptz
)`,
`create type cash_out_action_types AS ENUM (${actions})`,
`create table cash_out_actions (
id serial PRIMARY KEY,
session_id uuid REFERENCES cash_out_txs(session_id),
action cash_out_action_types NOT NULL,
created timestamptz NOT NULL default now()
)`,
`alter table dispenses add session_id uuid`,
`alter table dispenses drop constraint dispenses_transaction_id_fkey`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,19 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
`create table cash_out_hds (
session_id uuid PRIMARY KEY,
crypto_code text NOT NULL,
hd_serial integer NOT NULL,
swept boolean NOT NULL default false,
created timestamptz NOT NULL default now(),
unique (crypto_code, hd_serial)
)`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,14 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'alter table cash_out_hds add last_checked timestamptz not null default now()',
'alter table cash_out_hds add confirmed boolean not null default false',
'create index on cash_out_hds (confirmed, last_checked)',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,36 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'alter table bills rename device_fingerprint to device_id',
'alter table bills rename satoshis to crypto_atoms',
'alter table bills rename session_id to cash_in_txs_id',
'alter table cached_responses rename device_fingerprint to device_id',
'alter table cached_responses rename session_id to tx_id',
'alter table cash_in_txs rename session_id to id',
'alter table cash_in_txs rename device_fingerprint to device_id',
'alter table cash_out_actions rename session_id to cash_out_txs_id',
'alter table cash_out_hds rename session_id to id',
'alter table cash_out_txs rename session_id to id',
'alter table cash_out_txs rename device_fingerprint to device_id',
'alter table devices rename fingerprint to device_id',
'alter table dispenses rename session_id to cash_out_txs_id',
'alter table dispenses rename device_fingerprint to device_id',
'alter table machine_configs rename device_fingerprint to device_id',
'alter table machine_events rename device_fingerprint to device_id',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,17 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'alter table devices drop authorized',
'alter table devices drop unpair',
`create table paired_devices (
device_id text PRIMARY KEY,
created timestamptz NOT NULL default now()
)`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,20 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'drop table if exists cached_responses',
`create table idempotents (
request_id text PRIMARY KEY,
device_id text NOT NULL,
body json NOT NULL,
status integer NOT NULL,
pending boolean NOT NULL,
created timestamptz NOT NULL default now()
)`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,22 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'drop table if exists users',
`create table user_tokens (
token text PRIMARY KEY,
name text NOT NULL,
created timestamptz NOT NULL default now()
)`,
`create table one_time_passes (
token text PRIMARY KEY,
name text NOT NULL,
created timestamptz NOT NULL default now()
)`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,24 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'drop table if exists devices',
'drop table if exists paired_devices',
`create table devices (
device_id text PRIMARY KEY,
name text NOT NULL,
cashbox integer NOT NULL default 0,
cassette1 integer NOT NULL default 0,
cassette2 integer NOT NULL default 0,
paired boolean NOT NULL default TRUE,
display boolean NOT NULL default TRUE,
created timestamptz NOT NULL default now()
)`,
'alter table pairing_tokens add column name text NOT NULL',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,14 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'alter table dispenses drop column count1',
'alter table dispenses drop column count2',
'alter table dispenses drop column refill',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,17 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
`create table server_events (
id serial PRIMARY KEY,
event_type text NOT NULL,
created timestamptz NOT NULL default now()
)`,
'CREATE INDEX ON server_events (created)',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,16 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'alter table devices add column user_config_id int',
'alter table user_config add column created timestamptz NOT NULL default now()',
`ALTER TABLE devices ADD CONSTRAINT user_config_id
FOREIGN KEY (user_config_id)
REFERENCES user_config (id)`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,18 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'alter table cash_in_txs add column send boolean not null default false',
'alter table cash_in_txs rename currency_code to fiat_code',
'alter table bills rename currency_code to fiat_code',
'alter table bills rename denomination to fiat',
'alter table bills drop column to_address',
'alter table bills drop column device_id',
'alter table cash_out_txs rename currency_code to fiat_code',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,20 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'alter table cash_out_txs add column dispensed_1 integer',
'alter table cash_out_txs add column dispensed_2 integer',
'alter table cash_out_txs add column rejected_1 integer',
'alter table cash_out_txs add column rejected_2 integer',
'alter table cash_out_txs add column denomination_1 integer',
'alter table cash_out_txs add column denomination_2 integer',
'alter table cash_out_txs add column dispense_error text',
'alter table cash_out_txs add column dispense_time timestamptz',
'drop table dispenses',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,23 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'create sequence hd_indices_seq minvalue 0 maxvalue 2147483647',
'alter table cash_out_txs add column hd_index integer',
'alter sequence hd_indices_seq owned by cash_out_txs.hd_index',
"alter table cash_out_txs add column swept boolean not null default 'f'",
'alter table cash_out_txs drop column tx_hash',
'create unique index on cash_out_txs (hd_index)',
'drop table cash_out_hds',
'drop table cash_out_actions',
'drop table transactions',
'drop table idempotents',
'drop table machine_configs',
'drop table pending_transactions',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,20 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
"create type trade_type as enum ('buy', 'sell')",
`create table trades (
id serial PRIMARY KEY,
type trade_type not null,
crypto_code text not null,
crypto_atoms bigint not null,
fiat_code text not null,
created timestamptz NOT NULL default now()
)`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,20 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'alter table cash_in_txs add column send_confirmed boolean not null default false',
'alter table cash_in_txs add column device_time bigint not null',
'alter table cash_in_txs add column timedout boolean not null default false',
'alter table cash_in_txs add column send_time timestamptz',
'alter table cash_in_txs add column error_code text',
'alter table cash_in_txs add column operator_completed boolean not null default false',
'alter table cash_in_txs add column send_pending boolean not null default false',
'alter table cash_out_txs add column device_time bigint not null',
'alter table cash_out_txs add column timedout boolean not null default false',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,20 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
`create table cash_in_actions (
id serial primary key,
tx_id uuid not null,
action text not null,
error text,
error_code text,
tx_hash text,
created timestamptz not null default now()
)`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,41 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
`create table cash_out_actions (
id serial primary key,
tx_id uuid not null,
action text not null,
to_address text,
error text,
error_code text,
tx_hash text,
provisioned_1 integer,
provisioned_2 integer,
dispensed_1 integer,
dispensed_2 integer,
rejected_1 integer,
rejected_2 integer,
denomination_1 integer,
denomination_2 integer,
redeem boolean not null default false,
device_time bigint,
created timestamptz not null default now()
)`,
'alter table cash_out_txs drop column dispensed_1',
'alter table cash_out_txs drop column dispensed_2',
'alter table cash_out_txs drop column rejected_1',
'alter table cash_out_txs drop column rejected_2',
'alter table cash_out_txs drop column denomination_1',
'alter table cash_out_txs drop column denomination_2',
'alter table cash_out_txs drop column dispense_error',
'alter table cash_out_txs drop column dispense_time',
'alter table cash_out_txs add column dispense_confirmed boolean default false',
'alter table cash_out_txs rename column dispensed to dispense',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,10 @@
var db = require('./db')
exports.up = function (next) {
var sql = ['alter table user_config add column valid boolean not null']
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,15 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'alter table cash_out_txs add column provisioned_1 integer',
'alter table cash_out_txs add column provisioned_2 integer',
'alter table cash_out_txs add column denomination_1 integer',
'alter table cash_out_txs add column denomination_2 integer',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,10 @@
const db = require('./db')
exports.up = function (next) {
const sql = ['alter table devices drop column name']
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,29 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
`create table machine_pings (
id uuid PRIMARY KEY,
device_id text not null,
serial_number integer not null,
device_time timestamptz not null,
created timestamptz not null default now())`,
`create table aggregated_machine_pings (
id uuid PRIMARY KEY,
device_id text not null,
dropped_pings integer not null,
total_pings integer not null,
lag_sd_ms integer not null,
lag_min_ms integer not null,
lag_max_ms integer not null,
lag_median_ms integer not null,
day date not null)`,
'alter table machine_events drop column device_time',
'alter table machine_events add column device_time timestamptz',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,17 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'alter table cash_in_txs add column cash_in_fee numeric(14, 5) not null',
'alter table cash_in_txs add column cash_in_fee_crypto bigint not null',
'alter table cash_in_txs add column minimum_tx integer not null',
'alter table bills add column cash_in_fee numeric(14, 5) not null',
'alter table bills add column cash_in_fee_crypto bigint not null',
'alter table bills add column crypto_atoms_after_fee bigint not null',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,10 @@
var db = require('./db')
exports.up = function (next) {
var sql = ['alter table cash_out_txs add column error_code text']
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,26 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
`create table cash_out_refills (
id uuid PRIMARY KEY,
device_id text not null,
user_id integer not null,
cassette1 integer not null,
cassette2 integer not null,
denomination1 integer not null,
denomination2 integer not null,
created timestamptz not null default now())`,
`create table cash_in_refills (
id uuid PRIMARY KEY,
device_id text not null,
user_id integer not null,
cash_box_count integer not null,
created timestamptz not null default now())`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,33 @@
var db = require('./db')
var anonymous = require('../lib/constants').anonymousCustomer
exports.up = function (next) {
const sql = [
`create table customers (
id uuid PRIMARY KEY,
phone text unique,
phone_at timestamptz,
id_card_number text,
id_card_expiration date,
id_card_data json,
id_card_at timestamptz,
name text,
address text,
manually_verified boolean,
sanctions_check boolean,
front_facing_cam_path text,
front_facing_cam_at timestamptz,
id_card_image_path text,
id_card_image_at timestamptz,
created timestamptz NOT NULL DEFAULT now() )`,
`insert into customers (id, name) VALUES ( '${anonymous.uuid}','${anonymous.name}' )`,
`alter table cash_in_txs add column 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)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,19 @@
var db = require('./db')
exports.up = function (next) {
const sql = [
"create type compliance_types as enum ('manual', 'sanctions', 'sanctions_override')",
`create table compliance_authorizations (
id uuid PRIMARY KEY,
customer_id uuid REFERENCES customers (id),
compliance_type compliance_types NOT NULL,
authorized_at timestamptz NOT NULL,
authorized_by text REFERENCES user_tokens (token) )`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,14 @@
var db = require('./db')
exports.up = function (next) {
const sql = [
'alter table cash_in_txs drop column device_time',
'alter table cash_out_txs drop column device_time',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,14 @@
var db = require('./db')
exports.up = function (next) {
const sql = [
'alter table cash_in_txs add column tx_version integer not null',
'alter table cash_out_txs add column tx_version integer not null',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,14 @@
var db = require('./db')
exports.up = function (next) {
const sql = [
'alter table cash_out_txs add column published_at timestamptz',
'alter table cash_out_txs rename column confirmation_time to confirmed_at',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,55 @@
'use strict'
const db = require('./db')
exports.up = function (next) {
const sql = [
/**
* Replace all compliance_types enum values
*
* There is no ALTER TYPE name DROP/RENAME VALUE ... in psql
* This is a way to update all the existing enum values of an existing type
*
* @see {@link http://blog.yo1.dog/updating-enum-values-in-postgresql-the-safe-and-easy-way/}
*/
`create type compliance_type as enum
('authorized', 'sms', 'id_card_data', 'id_card_photo', 'sanctions_check', 'front_facing_cam', 'hard_limit')`,
'alter table compliance_authorizations alter column compliance_type set data type compliance_type using compliance_type::text::compliance_type',
'drop type compliance_types',
"create type verification_type as enum ('verified', 'blocked', 'automatic')",
'alter table customers drop column manually_verified ',
"alter table customers add column sms_override verification_type not null default 'automatic'",
'alter table customers add column sms_override_by text references user_tokens (token)',
'alter table customers add column sms_override_at timestamptz',
"alter table customers add column id_card_data_override verification_type not null default 'automatic'",
'alter table customers add column id_card_data_override_by text references user_tokens (token)',
'alter table customers add column id_card_data_override_at timestamptz',
"alter table customers add column id_card_photo_override verification_type not null default 'automatic'",
'alter table customers add column id_card_photo_override_by text references user_tokens (token)',
'alter table customers add column id_card_photo_override_at timestamptz',
"alter table customers add column front_facing_cam_override verification_type not null default 'automatic'",
'alter table customers add column front_facing_cam_override_by text references user_tokens (token)',
'alter table customers add column front_facing_cam_override_at timestamptz',
"alter table customers add column sanctions_check_override verification_type not null default 'automatic'",
'alter table customers add column sanctions_check_override_by text references user_tokens (token)',
'alter table customers add column sanctions_check_override_at timestamptz',
"alter table customers add column authorized_override verification_type not null default 'automatic'",
'alter table customers add column authorized_override_by text references user_tokens (token)',
'alter table customers add column authorized_override_at timestamptz',
'alter table customers add column authorized_at timestamptz',
'alter table customers add column sanctions_check_at timestamptz',
'alter table compliance_authorizations rename to compliance_overrides',
'alter table compliance_overrides add column verification verification_type not null',
'alter table compliance_overrides rename column authorized_at to override_at',
'alter table compliance_overrides rename column authorized_by to override_by',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,42 @@
'use strict'
const db = require('./db')
exports.up = function (next) {
const sql = [
'alter table customers rename column id_card_number to id_card_data_number',
'alter table customers rename column id_card_at to id_card_data_at',
'alter table customers rename column sanctions_check to sanctions',
'alter table customers rename column sanctions_check_at to sanctions_at',
'alter table customers rename column front_facing_cam_at to front_camera_at',
'alter table customers rename column front_facing_cam_path to front_camera_path',
'alter table customers rename column id_card_image_path to id_card_photo_path',
'alter table customers rename column id_card_image_at to id_card_photo_at',
'alter table customers rename column id_card_expiration to id_card_data_expiration',
'alter table customers rename column front_facing_cam_override to front_camera_override',
'alter table customers rename column front_facing_cam_override_by to front_camera_override_by',
'alter table customers rename column front_facing_cam_override_at to front_camera_override_at',
'alter table customers rename column sanctions_check_override to sanctions_override',
'alter table customers rename column sanctions_check_override_by to sanctions_override_by',
'alter table customers rename column sanctions_check_override_at to sanctions_override_at',
/**
* Replace all compliance_type enum values
*
* There is no ALTER TYPE name DROP/RENAME VALUE ... in psql
* This is a way to update all the existing enum values of an existing type
*
* @see {@link http://blog.yo1.dog/updating-enum-values-in-postgresql-the-safe-and-easy-way/}
*/
'alter type compliance_type rename to old_compliance_type',
`create type compliance_type as enum
('authorized', 'sms', 'id_card_data', 'id_card_photo', 'sanctions', 'front_camera', 'hard_limit')`,
'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)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,18 @@
var db = require('./db')
exports.up = function (next) {
const sql = [
`create table logs (
id uuid PRIMARY KEY,
device_id text,
log_level text,
timestamp timestamptz,
message text)`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,17 @@
var db = require('./db')
exports.up = function (next) {
const sql = [
`create table support_logs (
id uuid PRIMARY KEY,
device_id text,
timestamp timestamptz not null default now() )`,
'alter table logs add column server_timestamp timestamptz not null default now() ',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,18 @@
const db = require('./db')
// This migration was updated on v10.2
// it's from before 7.5 and we update one major version at a time
// Data migration was removed, keeping only the schema update
exports.up = function (next) {
const sql = [
'alter table devices add column name text',
'alter table devices alter column name set not null',
]
return db.multi(sql, next)
}
exports.down = function (next) {
const sql = ['alter table devices drop column name']
db.multi(sql, next)
}

View file

@ -0,0 +1,10 @@
const db = require('./db')
exports.up = function (next) {
const sql = ['alter table logs add column serial integer not null default 0']
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,20 @@
var db = require('./db')
exports.up = function (next) {
const sql = [
`create table sanctions_logs (
id uuid PRIMARY KEY,
device_id text not null,
sanctioned_id text not null,
sanctioned_alias_id text,
sanctioned_alias_full_name text not null,
customer_id uuid not null references customers,
created timestamptz not null default now() )`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,18 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'alter table cash_in_txs alter column cash_in_fee_crypto type numeric(30)',
'alter table cash_in_txs alter column crypto_atoms type numeric(30)',
'alter table cash_out_txs alter column crypto_atoms type numeric(30)',
'alter table trades alter column crypto_atoms type numeric(30)',
'alter table bills alter column crypto_atoms type numeric(30)',
'alter table bills alter column cash_in_fee_crypto type numeric(30)',
'alter table bills alter column crypto_atoms_after_fee type numeric(30)',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,13 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'alter table devices add column last_online timestamptz not null default now()',
"alter table devices add column location json not null default '{}'",
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,14 @@
var db = require('./db')
exports.up = function (next) {
const sql = [
'alter table cash_in_txs add column 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)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,13 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'alter table cash_out_txs add column layer_2_address text null',
'alter table cash_out_actions add column layer_2_address text null',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,12 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
"alter table cash_out_actions add device_id text not null default ''",
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,17 @@
const db = require('./db')
exports.up = function (next) {
var sql = [
'TRUNCATE TABLE machine_pings',
'ALTER TABLE machine_pings DROP id',
'ALTER TABLE machine_pings DROP serial_number',
'ALTER TABLE machine_pings ADD CONSTRAINT PK_device_id PRIMARY KEY (device_id)',
'ALTER TABLE machine_pings ADD CONSTRAINT U_device_id UNIQUE(device_id)',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,13 @@
var db = require('./db')
exports.up = function (next) {
const sql = ['alter table trades add column error text']
db.multi(sql, next)
}
exports.down = function (next) {
const sql = ['alter table trades drop column error']
db.multi(sql, next)
}

View file

@ -0,0 +1,16 @@
'use strict'
const db = require('./db')
exports.up = function (next) {
var sql = [
'ALTER TABLE cash_in_txs ADD COLUMN commission_percentage numeric(14, 5) null DEFAULT null',
'ALTER TABLE cash_out_txs ADD COLUMN commission_percentage numeric(14, 5) null DEFAULT null',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,16 @@
'use strict'
const db = require('./db')
exports.up = function (next) {
var sql = [
'ALTER TABLE cash_in_txs ADD COLUMN raw_ticker_price numeric(14, 5) null DEFAULT null',
'ALTER TABLE cash_out_txs ADD COLUMN raw_ticker_price numeric(14, 5) null DEFAULT null',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,15 @@
'use strict'
const db = require('./db')
exports.up = function (next) {
var sql = [
'ALTER TABLE cash_in_txs ADD COLUMN is_paper_wallet boolean null DEFAULT false',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,11 @@
const db = require('./db')
exports.up = function (next) {
var sql = ['TRUNCATE TABLE server_events']
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,17 @@
var db = require('./db')
exports.up = function (next) {
const sql = [
`create table blacklist (
crypto_code text not null,
address text not null,
unique (crypto_code, address)
)`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,11 @@
const db = require('./db')
exports.up = function (next) {
var sql = ['ALTER TABLE machine_pings RENAME COLUMN created to updated']
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,13 @@
const db = require('./db')
exports.up = function (next) {
var sql = [
"ALTER TABLE blacklist ADD COLUMN created_by_operator boolean not null default 't' ",
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,23 @@
var db = require('./db')
exports.up = function (next) {
const sql = [
'create table server_logs ( ' +
'id uuid PRIMARY KEY, ' +
'device_id text, ' +
'log_level text, ' +
'timestamp timestamptz DEFAULT now(), ' +
'message text, ' +
'meta json)',
`create table server_support_logs (
id uuid PRIMARY KEY,
timestamp timestamptz not null default now() )`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,13 @@
const db = require('./db')
exports.up = function (next) {
var sql = [
'ALTER TABLE cash_out_txs ADD COLUMN received_crypto_atoms numeric(30) null DEFAULT null',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,14 @@
const db = require('./db')
exports.up = function (next) {
var sql = [
'alter table devices add column version text',
'alter table devices add column model text',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,13 @@
const db = require('./db')
module.exports.up = function (next) {
var sql = [
'alter table user_config add column schema_version smallint not null DEFAULT 1',
]
db.multi(sql, next)
}
module.exports.down = function (next) {
next()
}

View file

@ -0,0 +1,11 @@
// This migration was actually a config update
// it's from before 7.5 and we update one major version at a time
// v10.2 is good enough to deprecate it
// file still has to exist so that the migration tool doesn't throw an error
module.exports.up = function (next) {
next()
}
module.exports.down = function (next) {
next()
}

View file

@ -0,0 +1,11 @@
const db = require('./db')
exports.up = function (next) {
var sql = ['ALTER TABLE customers ADD COLUMN suspended_until timestamptz']
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,17 @@
const db = require('./db')
exports.up = function (next) {
var sql = [
'ALTER TABLE customers ADD COLUMN us_ssn text',
'ALTER TABLE customers ADD COLUMN us_ssn_at timestamptz',
"ALTER TABLE customers ADD COLUMN us_ssn_override verification_type not null default 'automatic'",
'ALTER TABLE customers ADD COLUMN us_ssn_override_by text references user_tokens (token)',
'ALTER TABLE customers ADD COLUMN us_ssn_override_at timestamptz',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,14 @@
const db = require('./db')
exports.up = function (next) {
var sql = [
'ALTER TABLE user_tokens ADD COLUMN user_agent text',
'ALTER TABLE user_tokens ADD COLUMN ip_address inet',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,11 @@
const db = require('./db')
exports.up = function (next) {
var sql = ['ALTER TABLE user_tokens ADD COLUMN last_accessed timestamptz']
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,14 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
'drop table if exists support_logs',
'drop table if exists server_support_logs',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,18 @@
var db = require('./db')
exports.up = function (next) {
const sql = [
`CREATE TABLE coupons (
id UUID PRIMARY KEY,
code TEXT NOT NULL,
discount SMALLINT NOT NULL,
soft_deleted BOOLEAN DEFAULT false )`,
`CREATE UNIQUE INDEX uq_code ON coupons (code) WHERE NOT soft_deleted`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,14 @@
const db = require('./db')
exports.up = function (next) {
var sql = [
'ALTER TABLE cash_in_txs ADD COLUMN discount SMALLINT',
'ALTER TABLE cash_out_txs ADD COLUMN discount SMALLINT',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,15 @@
const db = require('./db')
exports.up = function (next) {
var sql = [
'ALTER TABLE bills DROP COLUMN crypto_atoms',
'ALTER TABLE bills DROP COLUMN cash_in_fee_crypto',
'ALTER TABLE bills DROP COLUMN crypto_atoms_after_fee',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,38 @@
var db = require('./db')
const singleQuotify = item => `'${item}'`
var types = [
'highValueTransaction',
'transaction',
'fiatBalance',
'cryptoBalance',
'compliance',
'error',
]
.map(singleQuotify)
.join(',')
exports.up = function (next) {
const sql = [
`
CREATE TYPE notification_type AS ENUM ${'(' + types + ')'};
CREATE TABLE "notifications" (
"id" uuid NOT NULL PRIMARY KEY,
"type" notification_type NOT NULL,
"detail" JSONB,
"message" TEXT NOT NULL,
"created" TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT CURRENT_TIMESTAMP,
"read" BOOLEAN NOT NULL DEFAULT 'false',
"valid" BOOLEAN NOT NULL DEFAULT 'true'
);
CREATE INDEX ON notifications (valid);
CREATE INDEX ON notifications (read);`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,16 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
`ALTER TABLE blacklist DROP CONSTRAINT blacklist_crypto_code_address_key`,
`ALTER TABLE blacklist ADD CONSTRAINT blacklist_crypto_code_address_created_by_operator_key UNIQUE (crypto_code, address, created_by_operator)`,
`CREATE INDEX ON blacklist (created_by_operator)`,
`REINDEX TABLE blacklist`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,11 @@
var db = require('./db')
exports.up = function (next) {
var sql = ['ALTER TABLE customers ADD COLUMN id_card_data_raw text']
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,26 @@
var db = require('./db')
exports.up = function (next) {
var sqls = [
`create table cashbox_batches (
id uuid PRIMARY KEY,
device_id text REFERENCES devices (device_id),
created timestamptz NOT NULL default now()
)`,
`ALTER TABLE bills ADD COLUMN legacy boolean DEFAULT false`,
`ALTER TABLE bills ADD COLUMN cashbox_batch_id uuid`,
`ALTER TABLE bills ADD CONSTRAINT cashbox_batch_id
FOREIGN KEY (cashbox_batch_id)
REFERENCES cashbox_batches (id)`,
`UPDATE bills SET legacy = 'true'`,
]
db.multi(sqls, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,22 @@
const db = require('./db')
exports.up = function (next) {
var sql = [
`CREATE TABLE cashout_tx_trades (
tx_id uuid REFERENCES cash_out_txs(id),
trade_id serial REFERENCES trades(id),
CONSTRAINT cashout_trade_pkey PRIMARY KEY (tx_id,trade_id)
)`,
`CREATE TABLE cashin_tx_trades (
tx_id uuid REFERENCES cash_in_txs(id),
trade_id serial REFERENCES trades(id),
CONSTRAINT cashin_trade_pkey PRIMARY KEY (tx_id,trade_id)
)`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,50 @@
const _ = require('lodash/fp')
var db = require('../lib/db')
const settingsLoader = require('../lib/new-settings-loader')
const configManager = require('../lib/new-config-manager')
exports.up = function (next) {
return db
.tx(async t => {
const settingsPromise = settingsLoader.loadLatestConfig()
const machinesPromise = t.any('SELECT device_id FROM devices')
const [config, machines] = await Promise.all([
settingsPromise,
machinesPromise,
])
const cryptoCodes = configManager.getCryptosFromWalletNamespace(config)
const deviceIds = _.map(_.get('device_id'))(machines)
const getZeroConfLimit = _.compose(_.get('zeroConfLimit'), it =>
configManager.getCashOut(it, config),
)
const zeroConfLimits = _.map(getZeroConfLimit)(deviceIds)
const configMin = _.min(zeroConfLimits)
const smallerZeroConf = _.isFinite(configMin) ? Number(configMin) : 0
_.forEach(cryptoCode => {
const walletConfig = configManager.getWalletSettings(cryptoCode, config)
const zeroConfLimit = _.get('zeroConfLimit', walletConfig)
if (_.isNil(zeroConfLimit)) {
config[`wallets_${cryptoCode}_zeroConfLimit`] = smallerZeroConf
}
}, cryptoCodes)
_.forEach(deviceId => {
const key = `cashOut_${deviceId}_zeroConfLimit`
if (_.has(key, config)) {
config[key] = null
}
})(deviceIds)
return settingsLoader.migrationSaveConfig(config)
})
.then(() => next())
.catch(err => next(err))
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,25 @@
var db = require('./db')
exports.up = function (next) {
var sqls = [
`CREATE TYPE cashbox_batch_type AS ENUM(
'cash-box-empty',
'cash-cassette-1-refill',
'cash-cassette-1-empty',
'cash-cassette-2-refill',
'cash-cassette-2-empty',
'cash-cassette-3-refill',
'cash-cassette-3-empty',
'cash-cassette-4-refill',
'cash-cassette-4-empty'
)`,
`ALTER TABLE cashbox_batches ADD COLUMN operation_type cashbox_batch_type NOT NULL`,
`ALTER TABLE cashbox_batches ADD COLUMN bill_count_override SMALLINT`,
`ALTER TABLE cashbox_batches ADD COLUMN performed_by VARCHAR(64)`,
]
db.multi(sqls, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,19 @@
const { migrationSaveConfig } = require('../lib/new-settings-loader')
exports.up = function (next) {
const triggersDefault = {
triggersConfig_expirationTime: 'Forever',
triggersConfig_automation: 'Automatic',
}
return migrationSaveConfig(triggersDefault)
.then(() => next())
.catch(err => {
console.log(err.message)
return next(err)
})
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,21 @@
const _ = require('lodash/fp')
const settingsLoader = require('../lib/new-settings-loader')
const configManager = require('../lib/new-config-manager')
exports.up = async function () {
const config = await settingsLoader.loadLatestConfig()
const cryptoCodes = configManager.getCryptosFromWalletNamespace(config)
_.forEach(cryptoCode => {
const key = `wallets_${cryptoCode}_zeroConf`
const zeroConfSetting = _.get(key, config)
if (cryptoCode === 'BTC' && zeroConfSetting === 'blockcypher') return
if (!_.isNil(zeroConfSetting) && zeroConfSetting !== 'none') {
config[key] = 'none'
}
}, cryptoCodes)
return settingsLoader.migrationSaveConfig(config)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,97 @@
var db = require('./db')
const constants = require('../lib/constants')
exports.up = function (next) {
var sql = [
`CREATE TYPE role AS ENUM('user', 'superuser')`,
`CREATE TABLE users (
id UUID PRIMARY KEY,
username TEXT NOT NULL UNIQUE,
password VARCHAR(100),
role role NOT NULL DEFAULT 'user',
enabled BOOLEAN DEFAULT true,
twofa_code VARCHAR(100),
temp_twofa_code VARCHAR(100),
created TIMESTAMPTZ NOT NULL DEFAULT now(),
last_accessed TIMESTAMPTZ NOT NULL DEFAULT now(),
last_accessed_from TEXT,
last_accessed_address INET )`,
`CREATE TABLE "user_sessions" (
"sid" VARCHAR NOT NULL COLLATE "default",
"sess" JSON NOT NULL,
"expire" TIMESTAMPTZ NOT NULL )
WITH (OIDS=FALSE)`,
`ALTER TABLE "user_sessions" ADD CONSTRAINT "session_pkey" PRIMARY KEY ("sid") NOT DEFERRABLE INITIALLY IMMEDIATE`,
`CREATE INDEX "IDX_session_expire" ON "user_sessions" ("expire")`,
`CREATE TYPE auth_token_type AS ENUM('reset_password', 'reset_twofa')`,
`CREATE TABLE auth_tokens (
token TEXT NOT NULL PRIMARY KEY,
type auth_token_type NOT NULL,
user_id UUID REFERENCES users(id) ON DELETE CASCADE,
expire TIMESTAMPTZ NOT NULL DEFAULT now() + interval '${constants.AUTH_TOKEN_EXPIRATION_TIME}',
CONSTRAINT unique_userid_type UNIQUE (user_id, type)
)`,
`CREATE TABLE user_register_tokens (
token TEXT NOT NULL PRIMARY KEY,
username TEXT NOT NULL UNIQUE,
role role DEFAULT 'user',
expire TIMESTAMPTZ NOT NULL DEFAULT now() + interval '${constants.REGISTRATION_TOKEN_EXPIRATION_TIME}'
)`,
// migrate values from customers which reference user_tokens for data persistence
`CREATE TABLE customer_compliance_persistence (
customer_id UUID NOT NULL PRIMARY KEY REFERENCES customers(id),
sms_override_by_old TEXT,
id_card_data_override_by_old TEXT,
id_card_photo_override_by_old TEXT,
front_camera_override_by_old TEXT,
sanctions_override_by_old TEXT,
authorized_override_by_old TEXT,
us_ssn_override_by_old TEXT
)`,
`INSERT INTO customer_compliance_persistence (
customer_id,
sms_override_by_old,
id_card_data_override_by_old,
id_card_photo_override_by_old,
front_camera_override_by_old,
sanctions_override_by_old,
authorized_override_by_old,
us_ssn_override_by_old
) SELECT id, sms_override_by, id_card_data_override_by, id_card_photo_override_by,
front_camera_override_by, sanctions_override_by, authorized_override_by, us_ssn_override_by
FROM customers`,
`ALTER TABLE customers DROP COLUMN sms_override_by`,
`ALTER TABLE customers DROP COLUMN id_card_data_override_by`,
`ALTER TABLE customers DROP COLUMN id_card_photo_override_by`,
`ALTER TABLE customers DROP COLUMN front_camera_override_by`,
`ALTER TABLE customers DROP COLUMN sanctions_override_by`,
`ALTER TABLE customers DROP COLUMN authorized_override_by`,
`ALTER TABLE customers DROP COLUMN us_ssn_override_by`,
`ALTER TABLE customers ADD COLUMN sms_override_by UUID REFERENCES users(id)`,
`ALTER TABLE customers ADD COLUMN id_card_data_override_by UUID REFERENCES users(id)`,
`ALTER TABLE customers ADD COLUMN id_card_photo_override_by UUID REFERENCES users(id)`,
`ALTER TABLE customers ADD COLUMN front_camera_override_by UUID REFERENCES users(id)`,
`ALTER TABLE customers ADD COLUMN sanctions_override_by UUID REFERENCES users(id)`,
`ALTER TABLE customers ADD COLUMN authorized_override_by UUID REFERENCES users(id)`,
`ALTER TABLE customers ADD COLUMN us_ssn_override_by UUID REFERENCES users(id)`,
// migrate values from compliance_overrides which reference user_tokens for data persistence
`CREATE TABLE compliance_overrides_persistence (
override_id UUID NOT NULL PRIMARY KEY REFERENCES compliance_overrides(id),
override_by_old TEXT
)`,
`INSERT INTO compliance_overrides_persistence (
override_id,
override_by_old
) SELECT id, override_by FROM compliance_overrides`,
`ALTER TABLE compliance_overrides DROP COLUMN override_by`,
`ALTER TABLE compliance_overrides ADD COLUMN override_by UUID REFERENCES users(id)`,
`DROP TABLE IF EXISTS one_time_passes`,
`DROP TABLE IF EXISTS user_tokens`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,89 @@
const _ = require('lodash/fp')
const {
migrationSaveConfig,
loadLatestConfig,
} = require('../lib/new-settings-loader')
const CASSETTE_MAX_CAPACITY = 500
exports.up = function (next) {
return loadLatestConfig()
.then(config => {
const fiatBalance1 = config.notifications_fiatBalanceCassette1
const fiatBalance2 = config.notifications_fiatBalanceCassette2
const fiatBalance3 = config.notifications_fiatBalanceCassette3
const fiatBalance4 = config.notifications_fiatBalanceCassette4
const overrides = config.notifications_fiatBalanceOverrides
const newConfig = {}
if (fiatBalance1) {
newConfig.notifications_fillingPercentageCassette1 = (
100 *
(fiatBalance1 / CASSETTE_MAX_CAPACITY)
).toFixed(0)
newConfig.notifications_fiatBalanceCassette1 = null
}
if (fiatBalance2) {
newConfig.notifications_fillingPercentageCassette2 = (
100 *
(fiatBalance2 / CASSETTE_MAX_CAPACITY)
).toFixed(0)
newConfig.notifications_fiatBalanceCassette2 = null
}
if (fiatBalance3) {
newConfig.notifications_fillingPercentageCassette3 = (
100 *
(fiatBalance3 / CASSETTE_MAX_CAPACITY)
).toFixed(0)
newConfig.notifications_fiatBalanceCassette3 = null
}
if (fiatBalance4) {
newConfig.notifications_fillingPercentageCassette4 = (
100 *
(fiatBalance4 / CASSETTE_MAX_CAPACITY)
).toFixed(0)
newConfig.notifications_fiatBalanceCassette4 = null
}
if (overrides) {
newConfig.notifications_fiatBalanceOverrides = _.map(override => {
const newOverride = {}
if (override.fiatBalanceCassette1) {
newOverride.fillingPercentageCassette1 = (
100 *
(override.fiatBalanceCassette1 / CASSETTE_MAX_CAPACITY)
).toFixed(0)
}
if (override.fiatBalanceCassette2) {
newOverride.fillingPercentageCassette2 = (
100 *
(override.fiatBalanceCassette2 / CASSETTE_MAX_CAPACITY)
).toFixed(0)
}
if (override.fiatBalanceCassette3) {
newOverride.fillingPercentageCassette3 = (
100 *
(override.fiatBalanceCassette3 / CASSETTE_MAX_CAPACITY)
).toFixed(0)
}
if (override.fiatBalanceCassette4) {
newOverride.fillingPercentageCassette4 = (
100 *
(override.fiatBalanceCassette4 / CASSETTE_MAX_CAPACITY)
).toFixed(0)
}
newOverride.machine = override.machine
newOverride.id = override.id
return newOverride
}, config.notifications_fiatBalanceOverrides)
}
return migrationSaveConfig(newConfig).then(() => next())
})
.catch(err => {
console.log(err.message)
return next(err)
})
}
module.exports.down = function (next) {
next()
}

View file

@ -0,0 +1,24 @@
const db = require('./db')
exports.up = function (next) {
const sql = [
`CREATE TABLE custom_info_requests(
id UUID PRIMARY KEY,
enabled BOOLEAN NOT NULL DEFAULT true,
custom_request JSONB
);
CREATE TABLE customers_custom_info_requests(
customer_id UUID REFERENCES customers,
info_request_id UUID REFERENCES custom_info_requests,
approved BOOLEAN,
customer_data JSONB NOT NULL,
PRIMARY KEY(customer_id, info_request_id)
);`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,17 @@
const _ = require('lodash/fp')
const settingsLoader = require('../lib/new-settings-loader')
exports.up = function (next) {
settingsLoader
.loadLatestConfig()
.then(config => {
if (!_.isEmpty(config)) config.locale_timezone = '0:0'
return settingsLoader.migrationSaveConfig(config)
})
.then(() => next())
.catch(err => next(err))
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,20 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
`ALTER TABLE user_register_tokens ADD COLUMN use_fido BOOLEAN DEFAULT false`,
`CREATE TABLE hardware_credentials (
id UUID PRIMARY KEY NOT NULL,
user_id UUID REFERENCES users(id) NOT NULL,
created TIMESTAMPTZ DEFAULT now(),
last_used TIMESTAMPTZ DEFAULT now(),
data JSONB NOT NULL
)`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,20 @@
const { migrationSaveConfig } = require('../lib/new-settings-loader')
exports.up = function (next) {
const newConfig = {
cashIn_cashboxReset: 'Manual',
}
return migrationSaveConfig(newConfig)
.then(() => next())
.catch(err => {
if (err.message === 'lamassu-server is not configured') {
return next()
}
console.log(err.message)
return next(err)
})
}
module.exports.down = function (next) {
next()
}

View file

@ -0,0 +1,21 @@
const db = require('./db')
const { migrationSaveConfig } = require('../lib/new-settings-loader')
exports.up = function (next) {
const sql = [`ALTER TYPE notification_type ADD VALUE 'security'`]
const newConfig = {}
newConfig.notifications_email_security = true
newConfig.notifications_sms_security = true
newConfig.notifications_notificationCenter_security = true
return migrationSaveConfig(newConfig)
.then(() => db.multi(sql, next))
.catch(err => {
return next(err)
})
}
module.exports.down = function (next) {
next()
}

View file

@ -0,0 +1,24 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
`CREATE TYPE transaction_batch_status AS ENUM('open', 'ready', 'failed', 'sent')`,
`CREATE TABLE transaction_batches (
id UUID PRIMARY KEY,
crypto_code TEXT NOT NULL,
status transaction_batch_status NOT NULL DEFAULT 'open',
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
closed_at TIMESTAMPTZ,
error_message TEXT
)`,
`ALTER TABLE cash_in_txs ADD COLUMN batch_id UUID REFERENCES transaction_batches(id)`,
`ALTER TABLE cash_in_txs ADD COLUMN batched BOOLEAN NOT NULL DEFAULT false`,
`ALTER TABLE cash_in_txs ADD COLUMN batch_time TIMESTAMPTZ`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,53 @@
var db = require('./db')
const pify = require('pify')
const fs = pify(require('fs'))
const hkdf = require('futoin-hkdf')
const state = require('../lib/middlewares/state')
const mnemonicHelpers = require('../lib/mnemonic-helpers')
function computeOperatorId(masterSeed) {
return hkdf(masterSeed, 16, {
salt: 'lamassu-server-salt',
info: 'operator-id',
}).toString('hex')
}
function getMnemonic() {
if (state.mnemonic) return Promise.resolve(state.mnemonic)
return fs.readFile(process.env.MNEMONIC_PATH, 'utf8').then(mnemonic => {
state.mnemonic = mnemonic
return mnemonic
})
}
function generateOperatorId() {
return getMnemonic()
.then(mnemonic => {
return computeOperatorId(mnemonicHelpers.toEntropyBuffer(mnemonic))
})
.catch(e => {
console.error('Error while computing operator id\n' + e)
throw e
})
}
exports.up = function (next) {
return generateOperatorId().then(operatorId => {
const sql = [
`CREATE TABLE operator_ids (
id serial PRIMARY KEY,
operator_id TEXT NOT NULL,
service TEXT NOT NULL
)`,
`INSERT INTO operator_ids (operator_id, service) VALUES ('${operatorId}','middleware')`,
`INSERT INTO operator_ids (operator_id, service) VALUES ('${operatorId}','coinatmradar')`,
`INSERT INTO operator_ids (operator_id, service) VALUES ('${operatorId}','authentication')`,
]
db.multi(sql, next)
})
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,35 @@
const {
migrationSaveConfig,
loadLatestConfig,
} = require('../lib/new-settings-loader')
const {
getCryptosFromWalletNamespace,
} = require('../lib/new-config-manager.js')
const { utils: coinUtils } = require('@lamassu/coins')
const _ = require('lodash/fp')
exports.up = function (next) {
loadLatestConfig()
.then(config => {
const newSettings = {}
const activeCryptos = getCryptosFromWalletNamespace(config)
if (!activeCryptos.length) return Promise.resolve()
_.map(crypto => {
const defaultUnit = _.head(
_.keys(coinUtils.getCryptoCurrency(crypto).units),
)
newSettings[`wallets_${crypto}_cryptoUnits`] = defaultUnit
return newSettings
}, activeCryptos)
return migrationSaveConfig(newSettings)
})
.then(() => next())
.catch(err => {
console.log(err.message)
return next(err)
})
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,18 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
`DELETE FROM blacklist WHERE created_by_operator = FALSE`,
`ALTER TABLE blacklist DROP CONSTRAINT blacklist_crypto_code_address_created_by_operator_key`,
`ALTER TABLE blacklist ADD CONSTRAINT blacklist_crypto_code_address_key UNIQUE (crypto_code, address)`,
`DROP INDEX blacklist_created_by_operator_idx`,
`ALTER TABLE blacklist DROP COLUMN created_by_operator`,
`CREATE INDEX cash_in_txs_to_address_idx ON cash_in_txs(to_address)`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,11 @@
const db = require('./db')
exports.up = function (next) {
const sql = [`ALTER TYPE compliance_type ADD VALUE 'us_ssn'`]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,26 @@
const db = require('./db')
exports.up = function (next) {
var sql = [
'DROP TABLE IF EXISTS machine_network_heartbeat',
'DROP TABLE IF EXISTS machine_network_performance',
`CREATE TABLE machine_network_performance (
device_id text PRIMARY KEY,
download_speed numeric NOT NULL,
created timestamptz NOT NULL default now()
)`,
`CREATE TABLE machine_network_heartbeat (
id uuid PRIMARY KEY,
device_id text not null,
average_response_time numeric NOT NULL,
average_packet_loss numeric NOT NULL,
created timestamptz NOT NULL default now()
)`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,22 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
`CREATE TABLE individual_discounts (
id UUID PRIMARY KEY,
customer_id UUID NOT NULL REFERENCES customers(id),
discount SMALLINT NOT NULL,
soft_deleted BOOLEAN DEFAULT false
)`,
`CREATE UNIQUE INDEX uq_individual_discount ON individual_discounts (customer_id) WHERE NOT soft_deleted`,
`CREATE TYPE discount_source AS ENUM('individualDiscount', 'promoCode')`,
`ALTER TABLE cash_in_txs ADD COLUMN discount_source discount_source`,
`ALTER TABLE cash_out_txs ADD COLUMN discount_source discount_source`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,19 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
`CREATE TYPE custom_message_event AS ENUM('sms_code', 'cash_out_dispense_ready')`,
`CREATE TABLE custom_messages (
id UUID PRIMARY KEY,
event custom_message_event UNIQUE NOT NULL,
message TEXT NOT NULL,
created TIMESTAMPTZ NOT NULL DEFAULT now()
)`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,13 @@
const db = require('./db')
exports.up = function (next) {
const sql = [
'ALTER TABLE cash_in_txs ADD COLUMN tx_customer_photo_at TIMESTAMPTZ, ADD COLUMN tx_customer_photo_path TEXT',
'ALTER TABLE cash_out_txs ADD COLUMN tx_customer_photo_at TIMESTAMPTZ, ADD COLUMN tx_customer_photo_path TEXT',
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

View file

@ -0,0 +1,21 @@
var db = require('./db')
exports.up = function (next) {
var sql = [
`CREATE TABLE customer_notes (
id UUID PRIMARY KEY,
customer_id UUID NOT NULL REFERENCES customers(id),
created TIMESTAMPTZ NOT NULL DEFAULT now(),
last_edited_at TIMESTAMPTZ,
last_edited_by UUID REFERENCES users(id),
title TEXT NOT NULL DEFAULT '',
content TEXT NOT NULL DEFAULT ''
)`,
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}

Some files were not shown because too many files have changed in this diff Show more