Files
ecom-dmb/apps/server/sql/migration/V20260920d__agent_llm_multi_provider.sql
T

26 lines
1.1 KiB
SQL
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 多提供商:去掉公司唯一 provider;model 归属 provider_id;允许跨提供商同名 model
ALTER TABLE `agent_company_llm_model`
ADD COLUMN `provider_id` bigint UNSIGNED NULL COMMENT '提供商ID' AFTER `company_id`;
UPDATE `agent_company_llm_model` m
INNER JOIN `agent_company_llm_provider` p ON p.company_id = m.company_id
SET m.provider_id = p.id
WHERE m.provider_id IS NULL;
DELETE FROM `agent_company_llm_model` WHERE `provider_id` IS NULL;
ALTER TABLE `agent_company_llm_model`
MODIFY COLUMN `provider_id` bigint UNSIGNED NOT NULL COMMENT '提供商ID';
ALTER TABLE `agent_company_llm_model`
DROP INDEX `uk_agent_llm_model_company_model`,
ADD UNIQUE KEY `uk_agent_llm_model_provider_model` (`provider_id`, `model`),
ADD KEY `idx_agent_llm_model_provider` (`provider_id`),
ADD CONSTRAINT `fk_agent_llm_model_provider`
FOREIGN KEY (`provider_id`) REFERENCES `agent_company_llm_provider` (`id`) ON DELETE CASCADE;
ALTER TABLE `agent_company_llm_provider`
DROP INDEX `uk_agent_llm_provider_company`,
ADD KEY `idx_agent_llm_provider_company` (`company_id`);