Feat: add "detail" row in notifications table migration This makes searching for specific notifications in the code like cashbox number easier because we don't need to scrub the notification message column anymore to search for notifications relating the cashbox 1 for example. Feat: clear notifications on cash cassette balance update
42 lines
932 B
JavaScript
42 lines
932 B
JavaScript
var db = require('./db')
|
|
|
|
function singleQuotify(item) {
|
|
return "'" + item + "'"
|
|
}
|
|
|
|
var types = [
|
|
'highValueTransaction',
|
|
'fiatBalance',
|
|
'cryptoBalance',
|
|
'compliance',
|
|
'error'
|
|
]
|
|
.map(singleQuotify)
|
|
.join(',')
|
|
|
|
exports.up = function (next) {
|
|
const sql = [
|
|
`
|
|
CREATE TYPE notification_type AS ENUM ${'(' + types + ')'};
|
|
CREATE TABLE IF NOT EXISTS "notifications" (
|
|
"id" uuid NOT NULL PRIMARY KEY,
|
|
"type" notification_type NOT NULL,
|
|
"detail" TEXT,
|
|
"device_id" TEXT NOT NULL,
|
|
"message" TEXT NOT NULL,
|
|
"created" time with time zone NOT NULL,
|
|
"read" BOOLEAN NOT NULL DEFAULT 'false',
|
|
CONSTRAINT fk_devices
|
|
FOREIGN KEY(device_id)
|
|
REFERENCES devices(device_id)
|
|
ON DELETE CASCADE
|
|
);
|
|
CREATE INDEX ON notifications (read);`
|
|
]
|
|
|
|
db.multi(sql, next)
|
|
}
|
|
|
|
exports.down = function (next) {
|
|
next()
|
|
}
|