Files
anchorage/internal/pkg/store/postgres/sqlc/nodes.sql.go
William Gill 12bf35caf8 anchorage v1.0 initial tree
Greenfield Go multi-tenant IPFS Pinning Service wire-compatible with the
IPFS Pinning Services API spec. Paired 1:1 with Kubo over localhost RPC,
clustered via embedded NATS JetStream, Postgres source-of-truth with
RLS-enforced tenancy, Fiber + huma v2 for the HTTP surface, Authentik
OIDC for session login with kid-rotated HS256 JWT API tokens.

Feature-complete against the 22-milestone build plan, including the
ship-it v1.0 gap items:

  * admin CLIs: drain/uncordon, maintenance, mint-token, rotate-key,
    prune-denylist, rebalance --dry-run, cache-stats, cluster-presences
  * TTL leader election via NATS KV, fence tokens, JetStream dedup
  * rebalancer (plan/apply split), reconciler, requeue sweeper
  * ristretto caches with NATS-backed cross-node invalidation
    (placements live-nodes + token denylist)
  * maintenance watchdog for stuck cluster-pause flag
  * Prometheus /metrics with CIDR ACL, HTTP/pin/scheduler/cache gauges
  * rate limiting: session (10/min) + anonymous global (120/min)
  * integration tests: rebalance, refcount multi-org, RLS belt
  * goreleaser (tar + deb/rpm/apk + Alpine Docker) targeting Gitea

Stack: Cobra/Viper, Fiber v2 + huma v2, embedded NATS JetStream,
pgx/sqlc/golang-migrate, ristretto, TypeID, prometheus/client_golang,
testcontainers-go.
2026-04-16 18:13:36 -05:00

202 lines
4.5 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.30.0
// source: nodes.sql
package sqlc
import (
"context"
"anchorage/internal/pkg/ids"
)
const drainNode = `-- name: DrainNode :exec
UPDATE nodes SET status = 'drained' WHERE id = $1
`
func (q *Queries) DrainNode(ctx context.Context, id ids.NodeID) error {
_, err := q.db.Exec(ctx, drainNode, id)
return err
}
const getNode = `-- name: GetNode :one
SELECT id, display_name, multiaddrs, rpc_url, status, last_seen_at, joined_at, updated_at FROM nodes WHERE id = $1
`
func (q *Queries) GetNode(ctx context.Context, id ids.NodeID) (Node, error) {
row := q.db.QueryRow(ctx, getNode, id)
var i Node
err := row.Scan(
&i.ID,
&i.DisplayName,
&i.Multiaddrs,
&i.RpcUrl,
&i.Status,
&i.LastSeenAt,
&i.JoinedAt,
&i.UpdatedAt,
)
return i, err
}
const listAllNodes = `-- name: ListAllNodes :many
SELECT id, display_name, multiaddrs, rpc_url, status, last_seen_at, joined_at, updated_at FROM nodes ORDER BY id
`
func (q *Queries) ListAllNodes(ctx context.Context) ([]Node, error) {
rows, err := q.db.Query(ctx, listAllNodes)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Node
for rows.Next() {
var i Node
if err := rows.Scan(
&i.ID,
&i.DisplayName,
&i.Multiaddrs,
&i.RpcUrl,
&i.Status,
&i.LastSeenAt,
&i.JoinedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const listLiveNodes = `-- name: ListLiveNodes :many
SELECT id, display_name, multiaddrs, rpc_url, status, last_seen_at, joined_at, updated_at FROM nodes WHERE status = 'up' ORDER BY id
`
func (q *Queries) ListLiveNodes(ctx context.Context) ([]Node, error) {
rows, err := q.db.Query(ctx, listLiveNodes)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Node
for rows.Next() {
var i Node
if err := rows.Scan(
&i.ID,
&i.DisplayName,
&i.Multiaddrs,
&i.RpcUrl,
&i.Status,
&i.LastSeenAt,
&i.JoinedAt,
&i.UpdatedAt,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const markNodeDown = `-- name: MarkNodeDown :exec
UPDATE nodes SET status = 'down' WHERE id = $1 AND status = 'up'
`
func (q *Queries) MarkNodeDown(ctx context.Context, id ids.NodeID) error {
_, err := q.db.Exec(ctx, markNodeDown, id)
return err
}
const markStaleNodesDown = `-- name: MarkStaleNodesDown :many
UPDATE nodes
SET status = 'down'
WHERE status = 'up' AND last_seen_at < (now() - make_interval(secs => $1))
RETURNING id
`
func (q *Queries) MarkStaleNodesDown(ctx context.Context, secs float64) ([]ids.NodeID, error) {
rows, err := q.db.Query(ctx, markStaleNodesDown, secs)
if err != nil {
return nil, err
}
defer rows.Close()
var items []ids.NodeID
for rows.Next() {
var id ids.NodeID
if err := rows.Scan(&id); err != nil {
return nil, err
}
items = append(items, id)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const touchNodeHeartbeat = `-- name: TouchNodeHeartbeat :exec
UPDATE nodes SET last_seen_at = now() WHERE id = $1
`
func (q *Queries) TouchNodeHeartbeat(ctx context.Context, id ids.NodeID) error {
_, err := q.db.Exec(ctx, touchNodeHeartbeat, id)
return err
}
const uncordonNode = `-- name: UncordonNode :exec
UPDATE nodes SET status = 'up' WHERE id = $1 AND status = 'drained'
`
func (q *Queries) UncordonNode(ctx context.Context, id ids.NodeID) error {
_, err := q.db.Exec(ctx, uncordonNode, id)
return err
}
const upsertNode = `-- name: UpsertNode :one
INSERT INTO nodes (id, display_name, multiaddrs, rpc_url, status)
VALUES ($1, $2, $3, $4, 'up')
ON CONFLICT (id) DO UPDATE
SET display_name = EXCLUDED.display_name,
multiaddrs = EXCLUDED.multiaddrs,
rpc_url = EXCLUDED.rpc_url,
status = CASE WHEN nodes.status = 'drained' THEN 'drained' ELSE 'up' END,
last_seen_at = now()
RETURNING id, display_name, multiaddrs, rpc_url, status, last_seen_at, joined_at, updated_at
`
type UpsertNodeParams struct {
ID ids.NodeID
DisplayName string
Multiaddrs []string
RpcUrl string
}
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (Node, error) {
row := q.db.QueryRow(ctx, upsertNode,
arg.ID,
arg.DisplayName,
arg.Multiaddrs,
arg.RpcUrl,
)
var i Node
err := row.Scan(
&i.ID,
&i.DisplayName,
&i.Multiaddrs,
&i.RpcUrl,
&i.Status,
&i.LastSeenAt,
&i.JoinedAt,
&i.UpdatedAt,
)
return i, err
}