Skip to content

Commit 547b836

Browse files
committed
sqldb+graph/db: fix UpsertNode bug
Account for the last_update field being null.
1 parent eb32b39 commit 547b836

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

graph/db/graph_test.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3361,18 +3361,7 @@ func TestAddChannelEdgeShellNodes(t *testing.T) {
33613361
require.ErrorIs(t, err, ErrEdgeAlreadyExist)
33623362

33633363
// Show that updating the shell node to a full node record works.
3364-
err = graph.AddLightningNode(node2)
3365-
_, ok := graph.V1Store.(*KVStore)
3366-
if ok {
3367-
require.NoError(t, err)
3368-
} else {
3369-
// Currently the SQL UpsertNode query prevents us from updating
3370-
// the node record if the current record's last_update field
3371-
// is null (which is the case for node2). This is a bug that
3372-
// will be fixed in the following commit.
3373-
require.ErrorContains(t, graph.AddLightningNode(node2),
3374-
"sql: no rows in result set")
3375-
}
3364+
require.NoError(t, graph.AddLightningNode(node2))
33763365
}
33773366

33783367
// TestNodePruningUpdateIndexDeletion tests that once a node has been removed

sqldb/sqlc/graph.sql.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqldb/sqlc/queries/graph.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ ON CONFLICT (pub_key, version)
1717
last_update = EXCLUDED.last_update,
1818
color = EXCLUDED.color,
1919
signature = EXCLUDED.signature
20-
WHERE EXCLUDED.last_update > nodes.last_update
20+
WHERE nodes.last_update IS NULL
21+
OR EXCLUDED.last_update > nodes.last_update
2122
RETURNING id;
2223

2324
-- name: GetNodeByPubKey :one

0 commit comments

Comments
 (0)