mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-14 12:02:27 +08:00
Keep the internal platform ID opencode_go. Product surface is OpenCode with account_mode zen|go, model-aware routing across Chat Completions, Responses, and Anthropic Messages, and X-OpenCode-Session derived from prompt_cache_key / metadata.user_id so prompt cache can hit. Unmatched models fall back to /v1/chat/completions. Related to #6742.
63 lines
2.7 KiB
SQL
63 lines
2.7 KiB
SQL
-- Add OpenCode as a first-class platform (account types Zen / GO).
|
|
--
|
|
-- 1. user_platform_quotas.platform CHECK
|
|
-- 2. composite_model_routes.target_platform CHECK
|
|
-- 3. channel_monitors / channel_monitor_request_templates provider CHECK
|
|
--
|
|
-- Runs after 237_add_minimax_platform.sql. DROP ... IF EXISTS + 幂等守卫保证可重入;
|
|
-- 新约束是 237 的超集,必须同时保留 MiniMax。
|
|
|
|
ALTER TABLE user_platform_quotas
|
|
DROP CONSTRAINT IF EXISTS user_platform_quotas_platform_check;
|
|
|
|
ALTER TABLE user_platform_quotas
|
|
ADD CONSTRAINT user_platform_quotas_platform_check
|
|
CHECK (platform IN ('anthropic', 'openai', 'gemini', 'antigravity', 'grok',
|
|
'kimi', 'zhipu', 'deepseek', 'minimax', 'opencode_go'));
|
|
|
|
ALTER TABLE composite_model_routes
|
|
DROP CONSTRAINT IF EXISTS composite_model_routes_target_platform_check;
|
|
|
|
ALTER TABLE composite_model_routes
|
|
ADD CONSTRAINT composite_model_routes_target_platform_check
|
|
CHECK (target_platform IN ('anthropic', 'openai', 'gemini', 'antigravity', 'grok',
|
|
'kimi', 'zhipu', 'deepseek', 'minimax', 'opencode_go'));
|
|
|
|
DO $$
|
|
DECLARE
|
|
monitor_constraint_def TEXT;
|
|
template_constraint_def TEXT;
|
|
BEGIN
|
|
SELECT pg_get_constraintdef(c.oid)
|
|
INTO monitor_constraint_def
|
|
FROM pg_constraint c
|
|
JOIN pg_class t ON t.oid = c.conrelid
|
|
WHERE t.relname = 'channel_monitors'
|
|
AND c.conname = 'channel_monitors_provider_check';
|
|
|
|
IF monitor_constraint_def IS NULL OR position('opencode_go' IN monitor_constraint_def) = 0 THEN
|
|
ALTER TABLE channel_monitors
|
|
DROP CONSTRAINT IF EXISTS channel_monitors_provider_check;
|
|
ALTER TABLE channel_monitors
|
|
ADD CONSTRAINT channel_monitors_provider_check
|
|
CHECK (provider IN ('openai', 'anthropic', 'gemini', 'grok',
|
|
'antigravity', 'kimi', 'zhipu', 'deepseek', 'minimax', 'opencode_go'));
|
|
END IF;
|
|
|
|
SELECT pg_get_constraintdef(c.oid)
|
|
INTO template_constraint_def
|
|
FROM pg_constraint c
|
|
JOIN pg_class t ON t.oid = c.conrelid
|
|
WHERE t.relname = 'channel_monitor_request_templates'
|
|
AND c.conname = 'channel_monitor_request_templates_provider_check';
|
|
|
|
IF template_constraint_def IS NULL OR position('opencode_go' IN template_constraint_def) = 0 THEN
|
|
ALTER TABLE channel_monitor_request_templates
|
|
DROP CONSTRAINT IF EXISTS channel_monitor_request_templates_provider_check;
|
|
ALTER TABLE channel_monitor_request_templates
|
|
ADD CONSTRAINT channel_monitor_request_templates_provider_check
|
|
CHECK (provider IN ('openai', 'anthropic', 'gemini', 'grok',
|
|
'antigravity', 'kimi', 'zhipu', 'deepseek', 'minimax', 'opencode_go'));
|
|
END IF;
|
|
END $$;
|