Migration sql changes (#199)
* safe migration script changes * lamassu migration script fixes
This commit is contained in:
parent
65ce8aee3d
commit
12c834469c
53 changed files with 500 additions and 346 deletions
|
|
@ -11,54 +11,54 @@ exports.up = function (next) {
|
|||
'published', 'authorized', 'confirmed'].map(singleQuotify).join(',')
|
||||
|
||||
var sqls = [
|
||||
'CREATE TYPE transaction_stage AS ENUM (' + stages + ')',
|
||||
'CREATE TYPE transaction_authority AS ENUM (' + authorizations + ')',
|
||||
db.defineEnum('transaction_stage', stages),
|
||||
db.defineEnum('transaction_authority', 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 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 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 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 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 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 INDEX ON dispenses (device_fingerprint)'
|
||||
db.ifColumn('dispenses', 'device_fingerprint', 'CREATE INDEX ON dispenses (device_fingerprint)')
|
||||
]
|
||||
|
||||
db.multi(sqls, next)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue