[management] Serve networks with peer-based routers from the SQLite network map (#7418)

The SQLite network-map query expanded a router's groups with from network_routers, json_each(peer_groups). That comma is an inner join, so a router row survives only when json_each returns at least one row. A router targeting an individual peer carries no groups — the write path stores NULL for a nil slice and '[]' for an empty one — and json_each yields nothing for either, so the join erased the router before it could be keyed by its peer. Postgres reads the same rows through a correlated subquery and was never affected.

The fix expands the groups with a left join, so the router survives with a NULL group_peers.peer_id and the existing scan loop keys it by router.Peer. Group routers still fan out one row per member.
This commit is contained in:
Maycon Santos
2026-09-04 08:14:02 +02:00
committed by GitHub
parent c2b5d211d9
commit 8dc4272519
2 changed files with 123 additions and 1 deletions
@@ -11,9 +11,11 @@ import (
)
const (
// Outer join: a groupless router must survive.
GetNetworkRouterQuery = `
select public_id, peer, network_id, masquerade, metric, enabled, peer_groups, group_peers.peer_id
from network_routers, json_each(peer_groups)
from network_routers
left join json_each(network_routers.peer_groups) on true
left join group_peers on group_peers.account_id=? and group_peers.group_id=json_each.value
where network_routers.account_id=?
`