Migration sql changes (#199)

* safe migration script changes

* lamassu migration script fixes
This commit is contained in:
Fabio Cigliano 2018-11-02 00:26:48 +13:00 committed by Josh Harvey
parent 65ce8aee3d
commit 12c834469c
53 changed files with 500 additions and 346 deletions

View file

@ -9,7 +9,7 @@ exports.up = function (next) {
.map(singleQuotify).join(',')
var sql = [
`create table cash_in_txs (
`CREATE TABLE IF NOT EXISTS 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 cash_out_txs (
`CREATE TABLE IF NOT EXISTS 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,15 +41,16 @@ exports.up = function (next) {
created timestamptz NOT NULL default now(),
confirmation_time timestamptz
)`,
`create type cash_out_action_types AS ENUM (${actions})`,
`create table cash_out_actions (
db.defineEnum('cash_out_action_types', actions),
`CREATE TABLE IF NOT EXISTS cash_out_actions (
id serial PRIMARY KEY,
session_id uuid REFERENCES cash_out_txs(session_id),
session_id uuid,
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.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')
]
db.multi(sql, next)
}