-- =============================================================
-- MIGRATION: AgentRouter API Key Support
-- Run di Supabase SQL Editor AFTER schema.sql
-- =============================================================

-- env_vars table sudah ada dan sudah support key-value arbitrary,
-- tidak perlu ALTER TABLE — AGENTROUTER_API_KEY disimpan sebagai row baru.

-- Update comment pada kolom key untuk dokumentasi key baru
COMMENT ON COLUMN env_vars.key IS
  'Predefined keys: OPENAI_API_KEY, ANTHROPIC_API_KEY, GOOGLE_AI_API_KEY, '
  'AGENTROUTER_API_KEY, '
  'SUPABASE_URL, SUPABASE_ANON_KEY, PREFERRED_AI_PROVIDER, PREFERRED_MODEL';

-- Update preferred_ai_provider check constraint di user_settings
-- agar menerima nilai "agentrouter"
ALTER TABLE user_settings
  DROP CONSTRAINT IF EXISTS user_settings_preferred_ai_provider_check;

ALTER TABLE user_settings
  ADD CONSTRAINT user_settings_preferred_ai_provider_check
  CHECK (preferred_ai_provider IN ('openai', 'anthropic', 'google', 'agentrouter', 'auto'));
