-- 分公司独立大模型配置 ALTER TABLE system_configs ADD COLUMN IF NOT EXISTS branch_code VARCHAR(50) REFERENCES branches(branch_code); ALTER TABLE system_configs DROP CONSTRAINT IF EXISTS system_configs_config_key_key; CREATE UNIQUE INDEX IF NOT EXISTS idx_system_configs_branch_key ON system_configs ((COALESCE(branch_code, '__GLOBAL__')), config_key); CREATE INDEX IF NOT EXISTS idx_system_configs_branch_code ON system_configs(branch_code); INSERT INTO system_configs (config_key, config_value, config_group, description, branch_code) SELECT 'branch_llm_config', jsonb_build_object( 'enabled', false, 'provider', 'ark', 'apiKeys', '', 'model', 'doubao-seed-2-0-lite-260428', 'imageModel', 'doubao-seedream-4-0-250828', 'imageSize', '512x512', 'baseUrl', 'https://ark.cn-beijing.volces.com/api/v3' ), 'ai', '分公司大模型配置', b.branch_code FROM branches b ON CONFLICT ((COALESCE(branch_code, '__GLOBAL__')), config_key) DO NOTHING; COMMENT ON COLUMN system_configs.branch_code IS '为空表示平台默认配置;非空表示分公司独立配置';