mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-10 05:12:14 +00:00
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>
27 lines
1.2 KiB
SQL
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;
|