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.
This commit is contained in:
flyemoji committed 2026-07-02 06:55:17 +09:00
1 parent c0d333bb98
commit 6368ab1914
1 file changed
+1 -1
+1 -1
View File
@@ -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) { func (p *PGRepo) MyServers(ctx context.Context, userID string) ([]MyServerView, error) {
const q = `SELECT s.name, COALESCE(sa.subdomain, ''), 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 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) WHERE s.deleted_at IS NULL AND (s.owner_id = $1 OR s.owner_id IS NULL)
ORDER BY s.name` ORDER BY s.name`