From 5b2166496e5f3ff2c4276e0b5b28f109c70673d5 Mon Sep 17 00:00:00 2001
From: Dan Goodliffe <dan.goodliffe@octal.co.uk>
Date: Wed, 15 Apr 2026 12:03:21 +0100
Subject: Replace use of crc32 for entity id

Entity value is MD5 hashed same as DB unique key, but the id itself is
now taken from the DB primary key which is sequence generated.
---
 src/sql/hostUpsert.sql | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

(limited to 'src/sql/hostUpsert.sql')

diff --git a/src/sql/hostUpsert.sql b/src/sql/hostUpsert.sql
index 18e8df8..d5ee11d 100644
--- a/src/sql/hostUpsert.sql
+++ b/src/sql/hostUpsert.sql
@@ -1,7 +1,9 @@
-INSERT INTO entities(id, type, value, detail)
-	VALUES ($1, 'host', $2, jsonb_build_object('sysname', $3::text, 'release', $4::text,
-	'version', $5::text, 'machine', $6::text, 'domainname', $7::text))
-ON CONFLICT ON CONSTRAINT pk_entities
+INSERT INTO entities(type, value, detail)
+	VALUES ('host', $1, jsonb_build_object('sysname', $2::text, 'release', $3::text,
+	'version', $4::text, 'machine', $5::text, 'domainname', $6::text))
+ON CONFLICT (md5(value))
 	DO UPDATE SET
-		detail = jsonb_build_object('sysname', $3::text, 'release', $4::text, 'version',
-		$5::text, 'machine', $6::text, 'domainname', $7::text)
+		detail = jsonb_build_object('sysname', $2::text, 'release', $3::text, 'version',
+		$4::text, 'machine', $5::text, 'domainname', $6::text)
+	RETURNING
+		id
-- 
cgit v1.3

