Files
HealthLog/prisma/migrations/0033_user_ai_provider_chain/migration.sql
T
Marc-André BombeckandClaude Opus 4.7 2611bb4fae feat(db): User.aiProviderChain for ordered fallback config
Add a JSONB column on the users table that stores an ordered list of
provider preferences for multi-provider redundancy. Each entry carries
{ providerType, priority, enabled }; credentials still live in the
dedicated encrypted columns so AES-256-GCM key rotation keeps working
unchanged. Null preserves the legacy single-provider resolution path.

Ships a defensive parser/serializer pair with a sensible default chain
(codex -> openai -> anthropic -> local -> admin-openai) so a malformed
JSON on disk falls back to the default rather than 500-ing insight
generation.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-10 00:20:12 +02:00

27 lines
1.2 KiB
SQL

-- v1.4.16 phase B5b: ordered fallback chain for multi-provider AI redundancy.
--
-- Up to v1.4.15 each user resolved exactly one AI provider per insight
-- request and a hard failure (401, 5xx, network timeout) bricked the
-- generation entirely. This column stores an ordered list of provider
-- preferences so the runner can fall through on hard failure to a
-- secondary configured provider.
--
-- Shape (JSONB so admin tools can grep/index later):
-- [
-- { "providerType": "codex", "priority": 1, "enabled": true },
-- { "providerType": "openai", "priority": 2, "enabled": true },
-- { "providerType": "anthropic", "priority": 3, "enabled": false }
-- ]
--
-- Credentials are NOT inlined here — they continue to live in the
-- dedicated encrypted columns (codex_*, ai_openai_key_encrypted,
-- ai_anthropic_key_encrypted, ai_local_key_encrypted) so AES-256-GCM
-- key-rotation via scripts/rotate-encryption-key.ts keeps working
-- unchanged. The chain is pure metadata: which providers, in what order.
--
-- NULL preserves the legacy single-provider behaviour driven by
-- users.ai_provider — no surprise migration of existing accounts.
ALTER TABLE "users"
ADD COLUMN "ai_provider_chain" JSONB;