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

@ -9,7 +9,7 @@ exports.up = function (next) {
.map(singleQuotify).join(',')
var sql = [
`CREATE TABLE IF NOT EXISTS cash_in_txs (
`create table cash_in_txs (
session_id uuid PRIMARY KEY,
device_fingerprint text NOT NULL,
to_address text NOT NULL,
@ -23,7 +23,7 @@ exports.up = function (next) {
error text,
created timestamptz NOT NULL default now()
)`,
`CREATE TABLE IF NOT EXISTS cash_out_txs (
`create table cash_out_txs (
session_id uuid PRIMARY KEY,
device_fingerprint text NOT NULL,
to_address text NOT NULL,
@ -32,7 +32,7 @@ exports.up = function (next) {
fiat numeric(14, 5) NOT NULL,
currency_code text NOT NULL,
tx_hash text,
status status_stage NOT NULL default 'notSeen',
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,
@ -41,16 +41,15 @@ exports.up = function (next) {
created timestamptz NOT NULL default now(),
confirmation_time timestamptz
)`,
db.defineEnum('cash_out_action_types', actions),
`CREATE TABLE IF NOT EXISTS cash_out_actions (
`create type cash_out_action_types AS ENUM (${actions})`,
`create table cash_out_actions (
id serial PRIMARY KEY,
session_id uuid,
session_id uuid REFERENCES cash_out_txs(session_id),
action cash_out_action_types NOT NULL,
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'),
db.addColumn('dispenses', 'session_id', 'uuid'),
db.dropConstraint('dispenses', 'dispenses_transaction_id_fkey')
`alter table dispenses add session_id uuid`,
`alter table dispenses drop constraint dispenses_transaction_id_fkey`
]
db.multi(sql, next)
}