From 194c07ec246eb8843d26cc9abc5cd44956c7669d Mon Sep 17 00:00:00 2001 From: andreas-unleash Date: Thu, 23 Feb 2023 11:16:13 +0200 Subject: [PATCH] Feat/notifications table (#3184) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Creates the `notifications` table and a `user_notifications` join table ## About the changes Closes # [1-720](https://linear.app/unleash/issue/1-720/db-table-for-notifications-and-real-store-with-link-to-event-store-to) ### Important files ## Discussion points --------- Signed-off-by: andreas-unleash --- ...0230222154915-create-notiications-table.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/migrations/20230222154915-create-notiications-table.js diff --git a/src/migrations/20230222154915-create-notiications-table.js b/src/migrations/20230222154915-create-notiications-table.js new file mode 100644 index 0000000000..a9fa980c09 --- /dev/null +++ b/src/migrations/20230222154915-create-notiications-table.js @@ -0,0 +1,32 @@ +'use strict'; + +exports.up = function (db, cb) { + db.runSql( + ` + CREATE TABLE IF NOT EXISTS notifications ( + id SERIAL PRIMARY KEY, + event_id INTEGER NOT NULL REFERENCES events (id), + created_by INTEGER NOT NULL REFERENCES users (id), + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now() + ); + + CREATE TABLE if not exists user_notifications + ( + notification_id INTEGER NOT NULL REFERENCES notifications (id), + user_id INTEGER NOT NULL REFERENCES users (id), + read_at TIMESTAMP WITH TIME ZONE, + PRIMARY KEY (notification_id, user_id) + ); + `, + cb, + ); +}; + +exports.down = function (db, cb) { + db.runSql( + ` + DROP TABLE IF EXISTS notifications; + DROP TABLE IF EXISTS user_notifications;`, + cb, + ); +};