From 7ebbf836cdde3dcc24f3db5d53d8c76257fbda98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Wed, 21 Feb 2024 11:31:41 +0000 Subject: [PATCH 1/3] chore: action_set_events db table migration --- .../20240221082758-action-events.js | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/migrations/20240221082758-action-events.js diff --git a/src/migrations/20240221082758-action-events.js b/src/migrations/20240221082758-action-events.js new file mode 100644 index 000000000000..777e7deaba77 --- /dev/null +++ b/src/migrations/20240221082758-action-events.js @@ -0,0 +1,33 @@ +exports.up = function (db, cb) { + db.runSql( + ` + CREATE TABLE IF NOT EXISTS action_set_events + ( + id SERIAL PRIMARY KEY NOT NULL, + action_set_id INTEGER NOT NULL, + observable_event_id INTEGER NOT NULL, + created_at TIMESTAMP WITH TIME ZONE NOT NULL DEFAULT now(), + state TEXT NOT NULL, + observable_event JSONB NOT NULL, + action_set JSONB NOT NULL + ); + + CREATE INDEX IF NOT EXISTS idx_action_set_events_action_set_id ON action_set_events(action_set_id); + CREATE INDEX IF NOT EXISTS idx_action_set_events_observable_event_id ON action_set_events(observable_event_id); + CREATE INDEX IF NOT EXISTS idx_action_set_events_action_set_id_state ON action_set_events(action_set_id, state); + `, + cb, + ); +}; + +exports.down = function (db, cb) { + db.runSql( + ` + DROP INDEX IF EXISTS idx_action_set_events_action_set_id; + DROP INDEX IF EXISTS idx_action_set_events_observable_event_id; + DROP INDEX IF EXISTS idx_action_set_events_action_set_id_state; + DROP TABLE IF EXISTS action_set_events; + `, + cb, + ); +}; From 5e63801a1da4dd28d08db19e653aeea2f6254e12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Wed, 21 Feb 2024 13:54:59 +0000 Subject: [PATCH 2/3] fix: remove redundant index as per PR comment --- src/migrations/20240221082758-action-events.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/migrations/20240221082758-action-events.js b/src/migrations/20240221082758-action-events.js index 777e7deaba77..87f273c07153 100644 --- a/src/migrations/20240221082758-action-events.js +++ b/src/migrations/20240221082758-action-events.js @@ -12,7 +12,6 @@ exports.up = function (db, cb) { action_set JSONB NOT NULL ); - CREATE INDEX IF NOT EXISTS idx_action_set_events_action_set_id ON action_set_events(action_set_id); CREATE INDEX IF NOT EXISTS idx_action_set_events_observable_event_id ON action_set_events(observable_event_id); CREATE INDEX IF NOT EXISTS idx_action_set_events_action_set_id_state ON action_set_events(action_set_id, state); `, From 9d5a2b72915e8cb4f0fd9ce8975accac2acf7aac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20G=C3=B3is?= Date: Wed, 21 Feb 2024 13:55:55 +0000 Subject: [PATCH 3/3] fix: remove index from down migration --- src/migrations/20240221082758-action-events.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/migrations/20240221082758-action-events.js b/src/migrations/20240221082758-action-events.js index 87f273c07153..ba6982fde2e2 100644 --- a/src/migrations/20240221082758-action-events.js +++ b/src/migrations/20240221082758-action-events.js @@ -22,7 +22,6 @@ exports.up = function (db, cb) { exports.down = function (db, cb) { db.runSql( ` - DROP INDEX IF EXISTS idx_action_set_events_action_set_id; DROP INDEX IF EXISTS idx_action_set_events_observable_event_id; DROP INDEX IF EXISTS idx_action_set_events_action_set_id_state; DROP TABLE IF EXISTS action_set_events;