From 504e7e796e064c7ca75abe5c52cb460b6ab99154 Mon Sep 17 00:00:00 2001 From: sjaanus Date: Thu, 27 Oct 2022 15:12:29 +0300 Subject: [PATCH] Add ability to merge --- src/lib/db/suggest-change-store.ts | 2 ++ src/migrations/20221810114644-add-suggest-changes-table.js | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/db/suggest-change-store.ts b/src/lib/db/suggest-change-store.ts index e169e692292..f778a92f3fe 100644 --- a/src/lib/db/suggest-change-store.ts +++ b/src/lib/db/suggest-change-store.ts @@ -230,6 +230,8 @@ export class SuggestChangeStore implements ISuggestChangeStore { suggest_change_set_id: changeSetID, created_by: userId, }) + .onConflict(['action', 'suggest_change_set_id', 'feature']) + .merge() .returning('id'); }; diff --git a/src/migrations/20221810114644-add-suggest-changes-table.js b/src/migrations/20221810114644-add-suggest-changes-table.js index 058e71e8f3f..1b4450afbdb 100644 --- a/src/migrations/20221810114644-add-suggest-changes-table.js +++ b/src/migrations/20221810114644-add-suggest-changes-table.js @@ -19,7 +19,8 @@ CREATE TABLE IF NOT EXISTS suggest_change ( payload jsonb not null default '[]'::jsonb, created_by integer not null references users (id) ON DELETE CASCADE, created_at timestamp default now(), - suggest_change_set_id integer NOT NULL REFERENCES suggest_change_set(id) ON DELETE CASCADE + suggest_change_set_id integer NOT NULL REFERENCES suggest_change_set(id) ON DELETE CASCADE, + UNIQUE (feature, action, suggest_change_set_id) ); `, callback,