From bd3ff7bab3a1cf6652781bb0742d085a6a8a0952 Mon Sep 17 00:00:00 2001 From: Christopher Kolstad Date: Fri, 6 Oct 2023 14:50:46 +0200 Subject: [PATCH] move trigger until after the insert. not before --- src/lib/db/event-store.ts | 4 +--- .../features/instance-stats/getProductionChanges.e2e.test.ts | 1 - .../20231004120900-create-changes-stats-table-and-trigger.js | 2 +- 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/lib/db/event-store.ts b/src/lib/db/event-store.ts index 37c303be1bb1..524d016e3294 100644 --- a/src/lib/db/event-store.ts +++ b/src/lib/db/event-store.ts @@ -146,9 +146,7 @@ class EventStore implements IEventStore { async batchStore(events: IBaseEvent[]): Promise { try { - await this.db(TABLE) - .insert(events.map(this.eventToDbRow)) - .returning(EVENT_COLUMNS); + await this.db(TABLE).insert(events.map(this.eventToDbRow)); } catch (error: unknown) { this.logger.warn(`Failed to store events: ${error}`); } diff --git a/src/lib/features/instance-stats/getProductionChanges.e2e.test.ts b/src/lib/features/instance-stats/getProductionChanges.e2e.test.ts index 21323cc54d58..3c8f4cf90c10 100644 --- a/src/lib/features/instance-stats/getProductionChanges.e2e.test.ts +++ b/src/lib/features/instance-stats/getProductionChanges.e2e.test.ts @@ -1,4 +1,3 @@ -import { createGetActiveUsers, type GetActiveUsers } from './getActiveUsers'; import dbInit, { type ITestDb } from '../../../test/e2e/helpers/database-init'; import getLogger from '../../../test/fixtures/no-logger'; import { diff --git a/src/migrations/20231004120900-create-changes-stats-table-and-trigger.js b/src/migrations/20231004120900-create-changes-stats-table-and-trigger.js index b02231b6806d..72846937b1c8 100644 --- a/src/migrations/20231004120900-create-changes-stats-table-and-trigger.js +++ b/src/migrations/20231004120900-create-changes-stats-table-and-trigger.js @@ -18,7 +18,7 @@ exports.up = function(db, cb) { $unleash_update_changes_counter$ LANGUAGE plpgsql; CREATE TRIGGER unleash_update_stat_environment_changes - BEFORE INSERT ON events + AFTER INSERT ON events FOR EACH ROW EXECUTE FUNCTION unleash_update_stat_environment_changes_counter(); `, cb); };