Files
accounted/supabase/migrations/20260826090000_api_keys_company_id_nullable.sql
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

17 lines
922 B
SQL

-- Migration: api_keys.company_id becomes nullable
--
-- Agent-first onboarding (#1814): a key minted from the OAuth popup before
-- the user's first company exists is stored unbound (company_id NULL) and
-- bound lazily by validateApiKey once a company exists. The column was made
-- NOT NULL by the dynamic loop in 20260330130000_multi_tenant_company_refactor
-- (line ~250 sets NOT NULL for every table in its list, api_keys included),
-- which nothing exercised until the companyless flow: the token endpoint's
-- insert violated it and every fresh Claude.ai authorization died with a 500
-- ("Authorization with Accounted failed", 2026-08-26).
--
-- Consumers already handle NULL: validateApiKey returns companyId
-- string|null, the MCP dispatcher answers NO_COMPANY_YET for company-scoped
-- tools on an unbound key, and /api/events fails closed.
ALTER TABLE public.api_keys ALTER COLUMN company_id DROP NOT NULL;