sqldb: update node query for v2

Here we update the UpdateNode query so that it can be used to insert
the new blockheight field for a v2 node.
This commit is contained in:
Elle Mouton committed 2026-02-13 07:21:20 +02:00
1 parent 3dfc835354
commit c61617200b
2 files changed
+40 -24

No files matched your search

+12 -6
View File
@@ -5,9 +5,9 @@
-- name: UpsertNode :one
INSERT INTO graph_nodes (
version, pub_key, alias, last_update, color, signature
version, pub_key, alias, last_update, block_height, color, signature
) VALUES (
$1, $2, $3, $4, $5, $6
$1, $2, $3, $4, $5, $6, $7
)
ON CONFLICT (pub_key, version)
-- Update the following fields if a conflict occurs on pub_key
@@ -15,10 +15,13 @@ ON CONFLICT (pub_key, version)
DO UPDATE SET
alias = EXCLUDED.alias,
last_update = EXCLUDED.last_update,
block_height = EXCLUDED.block_height,
color = EXCLUDED.color,
signature = EXCLUDED.signature
WHERE graph_nodes.last_update IS NULL
OR EXCLUDED.last_update > graph_nodes.last_update
WHERE (graph_nodes.last_update IS NULL
OR EXCLUDED.last_update > graph_nodes.last_update)
AND (graph_nodes.block_height IS NULL
OR EXCLUDED.block_height >= graph_nodes.block_height)
RETURNING id;
-- We use a separate upsert for our own node since we want to be less strict
@@ -26,9 +29,9 @@ RETURNING id;
-- update the record even if the last_update is the same as what we have.
-- name: UpsertSourceNode :one
INSERT INTO graph_nodes (
version, pub_key, alias, last_update, color, signature
version, pub_key, alias, last_update, block_height, color, signature
) VALUES (
$1, $2, $3, $4, $5, $6
$1, $2, $3, $4, $5, $6, $7
)
ON CONFLICT (pub_key, version)
-- Update the following fields if a conflict occurs on pub_key
@@ -36,10 +39,13 @@ ON CONFLICT (pub_key, version)
DO UPDATE SET
alias = EXCLUDED.alias,
last_update = EXCLUDED.last_update,
block_height = EXCLUDED.block_height,
color = EXCLUDED.color,
signature = EXCLUDED.signature
WHERE graph_nodes.last_update IS NULL
OR EXCLUDED.last_update >= graph_nodes.last_update
AND (graph_nodes.block_height IS NULL
OR EXCLUDED.block_height >= graph_nodes.block_height)
RETURNING id;
-- name: GetNodesByIDs :many