From 5f975bbad704ac60fe6a72404e45dcecd11f35ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Mon, 18 Dec 2023 13:22:28 +0000 Subject: [PATCH] chore: incoming webhooks and tokens migration (#5670) https://linear.app/unleash/issue/2-1699/db-create-migration-for-a-new-incoming-webhooks-table Adds a migration that creates 2 tables: - `incoming_webhooks` - `incoming_webhook_tokens` --- .../20231215105713-incoming-webhooks.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/migrations/20231215105713-incoming-webhooks.js diff --git a/src/migrations/20231215105713-incoming-webhooks.js b/src/migrations/20231215105713-incoming-webhooks.js new file mode 100644 index 0000000000..966da93774 --- /dev/null +++ b/src/migrations/20231215105713-incoming-webhooks.js @@ -0,0 +1,39 @@ +exports.up = function (db, cb) { + db.runSql( + ` + CREATE TABLE IF NOT EXISTS incoming_webhooks + ( + id SERIAL PRIMARY KEY NOT NULL, + enabled BOOLEAN DEFAULT true NOT NULL, + name TEXT NOT NULL, + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), + created_by_user_id INTEGER NOT NULL + ); + CREATE INDEX incoming_webhooks_enabled_idx ON incoming_webhooks(enabled); + + CREATE TABLE IF NOT EXISTS incoming_webhook_tokens + ( + id SERIAL PRIMARY KEY NOT NULL, + secret TEXT NOT NULL, + name TEXT NOT NULL, + incoming_webhook_id INTEGER NOT NULL REFERENCES incoming_webhooks(id) ON DELETE CASCADE, + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), + created_by_user_id INTEGER NOT NULL + ); + CREATE INDEX incoming_webhook_tokens_webhook_id_idx ON incoming_webhook_tokens(incoming_webhook_id); + `, + cb, + ); +}; + +exports.down = function (db, cb) { + db.runSql( + ` + DROP INDEX IF EXISTS incoming_webhooks_enabled_idx; + DROP INDEX IF EXISTS incoming_webhook_tokens_webhook_id_idx; + DROP TABLE IF EXISTS incoming_webhook_tokens; + DROP TABLE IF EXISTS incoming_webhooks; + `, + cb, + ); +};