1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-31 00:16:47 +01:00

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.
This commit is contained in:
Nuno Góis 2024-01-03 12:08:14 +00:00 committed by GitHub
parent fef6935d3a
commit 9c4a044543
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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