From 13d02685d8954de4e786f843b539f212fa1d91b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Wed, 17 Jul 2024 10:02:04 +0100 Subject: [PATCH] chore: db migration for integration events (#7604) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://linear.app/unleash/issue/2-2435/create-migration-for-a-new-integration-events-table Adds a DB migration that creates the `integration_events` table: - `id`: Auto-incrementing primary key; - `integration_id`: The id of the respective integration (i.e. integration configuration); - `created_at`: Date of insertion; - `state`: Integration event state, as text. Can be anything we'd like, but I'm thinking this will be something like: - Success ✅ - Failed ❌ - SuccessWithErrors ⚠️ - `state_details`: Expands on the previous column with more details, as text. Examples: - OK. Status code: 200 - Status code: 429 - Rate limit reached - No access token provided - `event`: The whole event object, stored as a JSON blob; - `details`: JSON blob with details about the integration execution. Will depend on the integration itself, but for example: - Webhook: Request body - Slack App: Message text and an array with all the channels we're posting to I think this gives us enough flexibility to cover all present and (possibly) future integrations, but I'd like to hear your thoughts. I'm also really torn on what to call this table: - `integration_events`: Consistent with the feature name. Addons are now called integrations, so this would be consistent with the new thing; - `addon_events`: Consistent with the existing `addons` table. --- .../20240716135038-integration-events.js | 29 +++++++++++++++++++ website/sidebars.js | 4 +-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/migrations/20240716135038-integration-events.js diff --git a/src/migrations/20240716135038-integration-events.js b/src/migrations/20240716135038-integration-events.js new file mode 100644 index 0000000000..11b9555a80 --- /dev/null +++ b/src/migrations/20240716135038-integration-events.js @@ -0,0 +1,29 @@ +exports.up = function (db, cb) { + db.runSql( + ` + CREATE TABLE IF NOT EXISTS integration_events + ( + id BIGSERIAL PRIMARY KEY NOT NULL, + integration_id INTEGER NOT NULL REFERENCES addons(id) ON DELETE CASCADE, + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), + state TEXT NOT NULL, + state_details TEXT NOT NULL, + event JSONB NOT NULL, + details JSONB NOT NULL + ); + + CREATE INDEX IF NOT EXISTS idx_integration_events_integration_id ON integration_events(integration_id); + `, + cb, + ); +}; + +exports.down = function (db, cb) { + db.runSql( + ` + DROP INDEX IF EXISTS idx_integration_events_integration_id; + DROP TABLE IF EXISTS integration_events; + `, + cb, + ); +}; diff --git a/website/sidebars.js b/website/sidebars.js index 12d2e0e83c..61a233d9c0 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -174,8 +174,8 @@ module.exports = { { type: 'doc', label: 'Examples', - id: 'feature-flag-tutorials/rust/examples' - } + id: 'feature-flag-tutorials/rust/examples', + }, ], }, {