Skip to content

Commit

Permalink
chore: db migration for integration events (#7604)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nunogois authored Jul 17, 2024
1 parent 4fb5469 commit 13d0268
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
29 changes: 29 additions & 0 deletions src/migrations/20240716135038-integration-events.js
Original file line number Diff line number Diff line change
@@ -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,
);
};
4 changes: 2 additions & 2 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ module.exports = {
{
type: 'doc',
label: 'Examples',
id: 'feature-flag-tutorials/rust/examples'
}
id: 'feature-flag-tutorials/rust/examples',
},
],
},
{
Expand Down

0 comments on commit 13d0268

Please sign in to comment.