lamassu-server/migrations/1607009558538-create-notifications-table.js
Cesar 3b3bdf839b Feat: crypto balance notifications saving in DB
Chore: add new column "detail" to transactions table migration

Feat: check if older notification is valid before sending new one

Feat: error saving to database

Fix: fix error when invalidating notification on
clearCryptoBalanceNotifications
Chre: code refactor in new-settings-loader for simplicity
Chore: refactor code on notifier and merge similar functions
2021-02-04 15:48:23 +00:00

43 lines
977 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,
"message" TEXT NOT NULL,
"created" TIMESTAMP WITH TIME ZONE NOT NULL,
"read" BOOLEAN NOT NULL DEFAULT 'false',
"valid" BOOLEAN NOT NULL DEFAULT 'true',
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()
}