From d88aaedea30729c39e9b6d40ef347e569b2efa21 Mon Sep 17 00:00:00 2001 From: Benoit Orihuela Date: Sat, 7 Dec 2024 12:40:44 +0100 Subject: [PATCH] feat(core): handle previous deleted attributes when creating a new one --- .../search/entity/service/EntityAttributeService.kt | 6 ++++++ .../V0_44__add_deleted_at_temporal_property.sql | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/search-service/src/main/kotlin/com/egm/stellio/search/entity/service/EntityAttributeService.kt b/search-service/src/main/kotlin/com/egm/stellio/search/entity/service/EntityAttributeService.kt index 276f72d6e..8cb659d7c 100644 --- a/search-service/src/main/kotlin/com/egm/stellio/search/entity/service/EntityAttributeService.kt +++ b/search-service/src/main/kotlin/com/egm/stellio/search/entity/service/EntityAttributeService.kt @@ -104,6 +104,12 @@ class EntityAttributeService( VALUES (:id, :entity_id, :attribute_name, :attribute_type, :attribute_value_type, :created_at, :dataset_id, :payload) + ON CONFLICT (entity_id, attribute_name, dataset_id) + DO UPDATE SET deleted_at = null, + attribute_type = :attribute_type, + attribute_value_type = :attribute_value_type, + created_at = :created_at, + payload = :payload """.trimIndent() ) .bind("id", attribute.id) diff --git a/search-service/src/main/resources/db/migration/V0_44__add_deleted_at_temporal_property.sql b/search-service/src/main/resources/db/migration/V0_44__add_deleted_at_temporal_property.sql index c0f608e4e..92f72d914 100644 --- a/search-service/src/main/resources/db/migration/V0_44__add_deleted_at_temporal_property.sql +++ b/search-service/src/main/resources/db/migration/V0_44__add_deleted_at_temporal_property.sql @@ -1,5 +1,13 @@ ALTER TABLE temporal_entity_attribute -ADD COLUMN deleted_at timestamp with time zone; + ADD COLUMN deleted_at timestamp with time zone; ALTER TABLE entity_payload -ADD COLUMN deleted_at timestamp with time zone; + ADD COLUMN deleted_at timestamp with time zone; + +DROP INDEX IF EXISTS temporal_entity_attribute_null_datasetid_uniqueness; + +ALTER TABLE temporal_entity_attribute + DROP CONSTRAINT temporal_entity_attribute_uniqueness; + +ALTER TABLE temporal_entity_attribute + ADD CONSTRAINT temporal_entity_attribute_uniqueness UNIQUE NULLS NOT DISTINCT (entity_id, attribute_name, dataset_id);