Files
1818web-hoduan/V5__add_provider_support.sql
2025-11-14 17:41:15 +08:00

83 lines
4.4 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.

-- ============================================================
-- V5: 添加多AI服务提供商支持
-- 描述: 支持接入多个AI服务提供商OpenAI格式、等
-- 作者: 1818AI
-- 日期: 2025-10-20
-- ============================================================
-- 1. 扩展points_config表添加服务商配置
ALTER TABLE `points_config`
ADD COLUMN `provider_type` VARCHAR(50) NOT NULL DEFAULT 'openai'
COMMENT 'AI服务提供商类型openai, ' AFTER `is_enabled`,
ADD COLUMN `provider_config` TEXT NULL
COMMENT '服务商特定配置JSON格式' AFTER `provider_type`;
-- 2. 扩展ai_task表添加服务商相关字段
ALTER TABLE `ai_task`
ADD COLUMN `provider_type` VARCHAR(50) NULL
COMMENT 'AI服务提供商类型' AFTER `task_type`,
ADD COLUMN `provider_task_id` VARCHAR(100) NULL
COMMENT '服务商返回的任务ID' AFTER `provider_type`,
ADD COLUMN `provider_response` TEXT NULL
COMMENT '服务商原始响应JSON' AFTER `provider_task_id`;
-- 3. 添加索引以优化查询性能
CREATE INDEX `idx_provider_task_id` ON `ai_task`(`provider_task_id`);
CREATE INDEX `idx_provider_type_status` ON `ai_task`(`provider_type`, `status`);
-- 4. 更新现有数据设置默认provider_type为openai
UPDATE `ai_task` SET `provider_type` = 'openai' WHERE `provider_type` IS NULL;
UPDATE `points_config` SET `provider_type` = 'openai' WHERE `provider_type` = 'openai';
-- 5. 插入模型配置(文生视频 + 图生视频)
INSERT INTO `points_config`
(model_name, points_cost, description, is_enabled, provider_type, provider_config, create_time, update_time)
VALUES
-- Sora2 文生视频webappId: 1973555977595301890
('rh_sora2_text_portrait', 160, ' Sora2 文生视频-竖屏10秒', 1, '',
'{"webappId":"1973555977595301890","taskType":"text2video","model":"portrait","duration":10}', NOW(), NOW()),
('rh_sora2_text_landscape', 160, ' Sora2 文生视频-横屏10秒', 1, '',
'{"webappId":"1973555977595301890","taskType":"text2video","model":"landscape","duration":10}', NOW(), NOW()),
('rh_sora2_text_portrait_hd', 420, ' Sora2 文生视频-高清竖屏10秒', 1, '',
'{"webappId":"1973555977595301890","taskType":"text2video","model":"portrait-hd","duration":10}', NOW(), NOW()),
('rh_sora2_text_landscape_hd', 420, ' Sora2 文生视频-高清横屏10秒', 1, '',
'{"webappId":"1973555977595301890","taskType":"text2video","model":"landscape-hd","duration":10}', NOW(), NOW()),
-- Sora2 图生视频webappId: 1973555366057390081
('rh_sora2_img_portrait', 180, ' Sora2 图生视频-竖屏10秒', 1, '',
'{"webappId":"1973555366057390081","taskType":"image2video","model":"portrait","duration":10}', NOW(), NOW()),
('rh_sora2_img_landscape', 180, ' Sora2 图生视频-横屏10秒', 1, '',
'{"webappId":"1973555366057390081","taskType":"image2video","model":"landscape","duration":10}', NOW(), NOW()),
('rh_sora2_img_portrait_hd', 480, ' Sora2 图生视频-高清竖屏10秒', 1, '',
'{"webappId":"1973555366057390081","taskType":"image2video","model":"portrait-hd","duration":10}', NOW(), NOW()),
('rh_sora2_img_landscape_hd', 480, ' Sora2 图生视频-高清横屏10秒', 1, '',
'{"webappId":"1973555366057390081","taskType":"image2video","model":"landscape-hd","duration":10}', NOW(), NOW()),
-- 15秒版本
('rh_sora2_text_portrait_15s', 260, ' Sora2 文生视频-竖屏15秒', 1, '',
'{"webappId":"1973555977595301890","taskType":"text2video","model":"portrait","duration":15}', NOW(), NOW()),
('rh_sora2_text_landscape_15s', 260, ' Sora2 文生视频-横屏15秒', 1, '',
'{"webappId":"1973555977595301890","taskType":"text2video","model":"landscape","duration":15}', NOW(), NOW()),
('rh_sora2_img_portrait_15s', 280, ' Sora2 图生视频-竖屏15秒', 1, '',
'{"webappId":"1973555366057390081","taskType":"image2video","model":"portrait","duration":15}', NOW(), NOW()),
('rh_sora2_img_landscape_15s', 280, ' Sora2 图生视频-横屏15秒', 1, '',
'{"webappId":"1973555366057390081","taskType":"image2video","model":"landscape","duration":15}', NOW(), NOW())
ON DUPLICATE KEY UPDATE
description = VALUES(description),
provider_config = VALUES(provider_config);
-- 6. 记录迁移日志
INSERT INTO `migration_log` (`version`, `description`, `executed_at`)
VALUES ('V5', '添加多AI服务提供商支持OpenAI、', NOW())
ON DUPLICATE KEY UPDATE `executed_at` = NOW();