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

+28 -18
View File
@@ -3673,9 +3673,9 @@ const upsertNode = `-- 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
@@ -3683,20 +3683,24 @@ 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
`
type UpsertNodeParams struct {
Version int16
PubKey []byte
Alias sql.NullString
LastUpdate sql.NullInt64
Color sql.NullString
Signature []byte
Version int16
PubKey []byte
Alias sql.NullString
LastUpdate sql.NullInt64
BlockHeight sql.NullInt64
Color sql.NullString
Signature []byte
}
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
@@ -3705,6 +3709,7 @@ func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64,
arg.PubKey,
arg.Alias,
arg.LastUpdate,
arg.BlockHeight,
arg.Color,
arg.Signature,
)
@@ -3801,9 +3806,9 @@ func (q *Queries) UpsertPruneLogEntry(ctx context.Context, arg UpsertPruneLogEnt
const upsertSourceNode = `-- 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
@@ -3811,20 +3816,24 @@ 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
`
type UpsertSourceNodeParams struct {
Version int16
PubKey []byte
Alias sql.NullString
LastUpdate sql.NullInt64
Color sql.NullString
Signature []byte
Version int16
PubKey []byte
Alias sql.NullString
LastUpdate sql.NullInt64
BlockHeight sql.NullInt64
Color sql.NullString
Signature []byte
}
// We use a separate upsert for our own node since we want to be less strict
@@ -3836,6 +3845,7 @@ func (q *Queries) UpsertSourceNode(ctx context.Context, arg UpsertSourceNodePara
arg.PubKey,
arg.Alias,
arg.LastUpdate,
arg.BlockHeight,
arg.Color,
arg.Signature,
)
+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