Unverified Commit 6368ab19 authored by Minseong Choi's avatar Minseong Choi 💬
Browse files

fix(api): coalesce MyServers owned flag so ownerless rows do not 500

The MyServers query lists both a user's own servers and unclaimed (owner_id IS NULL) servers, but computed owned as s.owner_id = $1. For an ownerless row that comparison is SQL NULL, which fails to scan into the Go bool and 500s the whole listing. Wrap it in COALESCE(..., false) so an ownerless row reports owned=false while still surfacing as claimable.
parent c0d333bb
Loading
Loading
Loading
Loading
+1 −1
Changes for internal/api/pgrepo.go: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -319,7 +319,7 @@ func (p *PGRepo) RecordJoin(ctx context.Context, name, mcUUID string) error {

func (p *PGRepo) MyServers(ctx context.Context, userID string) ([]MyServerView, error) {
	const q = `SELECT s.name, COALESCE(sa.subdomain, ''),
		(s.owner_id = $1) AS owned, (s.owner_id IS NULL) AS claimable, COALESCE(s.cached_phase, '')
		COALESCE(s.owner_id = $1, false) AS owned, (s.owner_id IS NULL) AS claimable, COALESCE(s.cached_phase, '')
		FROM servers s LEFT JOIN server_aliases sa ON sa.server_name = s.name
		WHERE s.deleted_at IS NULL AND (s.owner_id = $1 OR s.owner_id IS NULL)
		ORDER BY s.name`