From f4a2bba62cf237cc4d935ba23b581265459b0ef8 Mon Sep 17 00:00:00 2001 From: Djamel Ferhod Date: Wed, 19 Jun 2024 17:20:46 +0200 Subject: [PATCH] all tests pass --- .../20240617151644-pgwar-community-entity-labels-up.sql | 7 +++++-- .../test-pgwar-community-entity-label.sql | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/database/migrations/sqls/20240617151644-pgwar-community-entity-labels-up.sql b/database/migrations/sqls/20240617151644-pgwar-community-entity-labels-up.sql index c86b935ed..56a538311 100644 --- a/database/migrations/sqls/20240617151644-pgwar-community-entity-labels-up.sql +++ b/database/migrations/sqls/20240617151644-pgwar-community-entity-labels-up.sql @@ -92,9 +92,10 @@ CREATE OR REPLACE FUNCTION pgwar.update_community_entity_label_on_project_entity DECLARE label text; BEGIN - IF NEW.fk_project != 0 THEN - SELECT pgwar.get_most_frequent_entity_label(NEW.pk_entity) INTO label; + IF NEW.fk_project != 0 OR OLD.fk_project !=0 THEN + IF tg_op = 'UPDATE' AND OLD.entity_label != NEW.entity_label THEN + SELECT pgwar.get_most_frequent_entity_label(NEW.pk_entity) INTO label; PERFORM pgwar.upsert_community_entity_preview(( NEW.pk_entity, @@ -113,6 +114,7 @@ BEGIN NEW.tmsp_last_modification)::pgwar.entity_preview ); ELSEIF tg_op = 'INSERT' THEN + SELECT pgwar.get_most_frequent_entity_label(NEW.pk_entity) INTO label; PERFORM pgwar.upsert_community_entity_preview(( NEW.pk_entity, @@ -131,6 +133,7 @@ BEGIN NEW.tmsp_last_modification)::pgwar.entity_preview ); ELSE + SELECT pgwar.get_most_frequent_entity_label(OLD.pk_entity) INTO label; UPDATE pgwar.entity_preview SET entity_label = label WHERE fk_project = 0 AND pk_entity = OLD.pk_entity; diff --git a/database/test/integration/pgwar-community-entity-label/test-pgwar-community-entity-label.sql b/database/test/integration/pgwar-community-entity-label/test-pgwar-community-entity-label.sql index dcd40ad93..eaa752235 100644 --- a/database/test/integration/pgwar-community-entity-label/test-pgwar-community-entity-label.sql +++ b/database/test/integration/pgwar-community-entity-label/test-pgwar-community-entity-label.sql @@ -322,7 +322,7 @@ WHERE notes = '_1'; SELECT is( ep.entity_label, 'Label 1bis', - 'Assert community entity preview has Label 1bis' + 'Assert community entity preview has Label 1bis after inserts' ) FROM pgwar.entity_preview ep, information.resource r @@ -339,7 +339,7 @@ WHERE fk_project > 3; SELECT is( ep.entity_label, 'Label 1ter', - 'Assert community entity preview has Label 1ter' + 'Assert community entity preview has Label 1ter after updates' ) FROM pgwar.entity_preview ep, information.resource r @@ -355,7 +355,7 @@ WHERE fk_project > 1; SELECT is( ep.entity_label, 'Label 1', - 'Assert community entity preview has Label 1' + 'Assert community entity preview has Label 1 after deletes' ) FROM pgwar.entity_preview ep, information.resource r