1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-01 00:08:27 +01:00
unleash.unleash/src/migrations/20240102205517-observable-events.js
Nuno Góis 9c4a044543
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.
2024-01-03 12:08:14 +00:00

33 lines
1.3 KiB
JavaScript

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,
);
};