Show protocol enable state and which nodes have each protocol installed.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+19
-1
@@ -82,6 +82,18 @@ CREATE TABLE IF NOT EXISTS nodes (
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_nodes_status ON nodes(status);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS node_protocols (
|
||||
node_id UUID NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,
|
||||
protocol_id UUID NOT NULL REFERENCES protocols(id) ON DELETE CASCADE,
|
||||
installed BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
enabled BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
port INT NOT NULL DEFAULT 0,
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
PRIMARY KEY (node_id, protocol_id)
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS idx_node_protocols_protocol ON node_protocols(protocol_id);
|
||||
`
|
||||
_, err := db.Exec(schema)
|
||||
return err
|
||||
@@ -129,7 +141,7 @@ func SeedProtocols(db *sql.DB) error {
|
||||
for _, p := range defaults {
|
||||
_, err := db.Exec(`
|
||||
INSERT INTO protocols (code, name, description, port, enabled, sort_order)
|
||||
VALUES ($1, $2, $3, $4, TRUE, $5)
|
||||
VALUES ($1, $2, $3, $4, FALSE, $5)
|
||||
ON CONFLICT (code) DO NOTHING`,
|
||||
p.Code, p.Name, p.Description, p.Port, p.Sort,
|
||||
)
|
||||
@@ -185,6 +197,12 @@ UPDATE protocols SET enabled = NOT enabled, updated_at = NOW() WHERE id = $1`, i
|
||||
return err
|
||||
}
|
||||
|
||||
func SetProtocolEnabled(db *sql.DB, id uuid.UUID, enabled bool) error {
|
||||
_, err := db.Exec(`
|
||||
UPDATE protocols SET enabled = $2, updated_at = NOW() WHERE id = $1`, id, enabled)
|
||||
return err
|
||||
}
|
||||
|
||||
func GetStats(db *sql.DB) (models.DashboardStats, error) {
|
||||
var s models.DashboardStats
|
||||
err := db.QueryRow(`SELECT COUNT(*) FROM protocols`).Scan(&s.ProtocolsTotal)
|
||||
|
||||
Reference in New Issue
Block a user