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:
Rafael Taranto 2018-11-18 07:15:22 -02:00 committed by Josh Harvey
parent 9af204e609
commit 06f8c57608
58 changed files with 1516 additions and 567 deletions

View file

@ -11,54 +11,54 @@ exports.up = function (next) {
'published', 'authorized', 'confirmed'].map(singleQuotify).join(',')
var sqls = [
db.defineEnum('transaction_stage', stages),
db.defineEnum('transaction_authority', authorizations),
'CREATE TYPE transaction_stage AS ENUM (' + stages + ')',
'CREATE TYPE transaction_authority AS ENUM (' + authorizations + ')',
'CREATE TABLE IF NOT EXISTS 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 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 IF NOT EXISTS 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 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 IF NOT EXISTS 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 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() ' +
')',
db.ifColumn('dispenses', 'device_fingerprint', 'CREATE INDEX ON dispenses (device_fingerprint)')
'CREATE INDEX ON dispenses (device_fingerprint)'
]
db.multi(sqls, next)