From 9c4a04454366b06d476383b05e6719ddd70d9638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Wed, 3 Jan 2024 12:08:14 +0000 Subject: [PATCH] chore: observable events db migration (#5749) https://linear.app/unleash/issue/2-1773/db-create-migration-for-a-new-observable-events-table Adds a new DB migration to create a new `observable_events` table. Even though we are thinking long term with the `source` columns, the short term purpose of this table will be to store incoming webhook calls. --- .../20240102205517-observable-events.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/migrations/20240102205517-observable-events.js diff --git a/src/migrations/20240102205517-observable-events.js b/src/migrations/20240102205517-observable-events.js new file mode 100644 index 0000000000..06d1c49849 --- /dev/null +++ b/src/migrations/20240102205517-observable-events.js @@ -0,0 +1,32 @@ +exports.up = function (db, cb) { + db.runSql( + ` + CREATE TABLE IF NOT EXISTS observable_events + ( + id SERIAL PRIMARY KEY NOT NULL, + payload JSONB NOT NULL DEFAULT '{}'::jsonb, + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), + source TEXT NOT NULL, + source_id INTEGER NOT NULL, + created_by_incoming_webhook_token_id INTEGER, + announced BOOLEAN DEFAULT false NOT NULL + ); + CREATE INDEX observable_events_source_and_source_id_idx ON observable_events(source, source_id); + CREATE INDEX observable_events_created_by_incoming_webhook_token_id_idx ON observable_events(created_by_incoming_webhook_token_id); + CREATE INDEX observable_events_unannounced_idx ON observable_events(announced) WHERE announced = false; + `, + cb, + ); +}; + +exports.down = function (db, cb) { + db.runSql( + ` + DROP INDEX IF EXISTS observable_events_source_and_source_id_idx; + DROP INDEX IF EXISTS observable_events_created_by_incoming_webhook_token_id_idx; + DROP INDEX IF EXISTS observable_events_unannounced_idx; + DROP TABLE IF EXISTS observable_events; + `, + cb, + ); +};