Skip to content

Commit

Permalink
Don't overwrite fqdn and motd when upserting node
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbakker committed Jan 21, 2024
1 parent 98a5de2 commit 383f7c3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 deletions.
8 changes: 3 additions & 5 deletions internal/db/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ SELECT COUNT(*)
FROM node;

-- name: UpsertNode :one
INSERT INTO node(public_key, fqdn, motd)
VALUES(?, ?, ?)
INSERT INTO node(public_key)
VALUES(?)
ON CONFLICT(public_key)
DO UPDATE SET fqdn = EXCLUDED.fqdn,
motd = EXCLUDED.motd,
last_seen_at = unixepoch('subsec')
DO UPDATE SET last_seen_at = unixepoch('subsec')
RETURNING *;

-- name: UpdateNodeBootstrapInfo :exec
Expand Down
18 changes: 5 additions & 13 deletions internal/db/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions internal/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ func (r *NodesRepo) TrackDHTNode(ctx context.Context, node *dht.Node) (*models.N
defer tx.Rollback()

q := r.q.WithTx(tx)
dbNode, err := q.UpsertNode(ctx, &db.UpsertNodeParams{
PublicKey: (*db.PublicKey)(node.PublicKey),
})
dbNode, err := q.UpsertNode(ctx, (*db.PublicKey)(node.PublicKey))
if err != nil {
return nil, fmt.Errorf("upsert node: %w", err)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/repo/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestAddNode(t *testing.T) {
defer close()

node := generateNode(t)
dbNode, err := repo.q.UpsertNode(ctx, &db.UpsertNodeParams{PublicKey: (*db.PublicKey)(node.PublicKey)})
dbNode, err := repo.q.UpsertNode(ctx, (*db.PublicKey)(node.PublicKey))
if err != nil {
t.Fatal(err)
}
Expand All @@ -93,7 +93,7 @@ func TestHasNodeByPublicKey(t *testing.T) {
defer close()

node := generateNode(t)
_, err := repo.q.UpsertNode(ctx, &db.UpsertNodeParams{PublicKey: (*db.PublicKey)(node.PublicKey)})
_, err := repo.q.UpsertNode(ctx, (*db.PublicKey)(node.PublicKey))
if err != nil {
t.Fatal(err)
}
Expand All @@ -120,7 +120,7 @@ func TestPongNonExistentNode(t *testing.T) {
defer close()

pk := generatePublicKey(t)
_, err := repo.q.UpsertNode(ctx, &db.UpsertNodeParams{PublicKey: (*db.PublicKey)(pk)})
_, err := repo.q.UpsertNode(ctx, (*db.PublicKey)(pk))
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 383f7c3

Please sign in to comment.