diff options
| author | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-04-15 12:03:21 +0100 |
|---|---|---|
| committer | Dan Goodliffe <dan.goodliffe@octal.co.uk> | 2026-04-15 12:05:20 +0100 |
| commit | 5b2166496e5f3ff2c4276e0b5b28f109c70673d5 (patch) | |
| tree | 93c351f6ef7d3d60d60247d5dbf531496f14a06c /src/sql | |
| parent | 3ce6cf305572709332d7329674ec45c987a093ad (diff) | |
| download | webstat-5b2166496e5f3ff2c4276e0b5b28f109c70673d5.tar.bz2 webstat-5b2166496e5f3ff2c4276e0b5b28f109c70673d5.tar.xz webstat-5b2166496e5f3ff2c4276e0b5b28f109c70673d5.zip | |
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.
Diffstat (limited to 'src/sql')
| -rw-r--r-- | src/sql/entityInsert.sql | 6 | ||||
| -rw-r--r-- | src/sql/hostUpsert.sql | 14 |
2 files changed, 10 insertions, 10 deletions
diff --git a/src/sql/entityInsert.sql b/src/sql/entityInsert.sql index 8e25810..f518617 100644 --- a/src/sql/entityInsert.sql +++ b/src/sql/entityInsert.sql @@ -1,4 +1,2 @@ -INSERT INTO entities(id, type, value) - VALUES (?, ?, ?) -ON CONFLICT - DO NOTHING +SELECT + entity(?, ?) 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 |
