044_extend_models_for_local_models.sql 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. -- 迁移文件: 044_extend_models_for_local_models.sql
  2. -- 描述: 扩展models表支持本地模型功能
  3. -- 需求: 3.1, 3.2, 3.3, 3.4
  4. -- ============================================
  5. -- 正向迁移: 添加本地模型相关字段和索引
  6. -- ============================================
  7. -- 添加is_local字段:区分本地和云端模型
  8. ALTER TABLE aigcspace.models ADD COLUMN IF NOT EXISTS is_local BOOLEAN NOT NULL DEFAULT FALSE;
  9. COMMENT ON COLUMN aigcspace.models.is_local IS '是否为本地模型';
  10. -- 添加user_id字段:关联上传用户
  11. ALTER TABLE aigcspace.models ADD COLUMN IF NOT EXISTS user_id VARCHAR(50) NULL;
  12. COMMENT ON COLUMN aigcspace.models.user_id IS '上传用户ID(本地模型必填)';
  13. -- 添加base_url字段:存储本地模型API地址
  14. ALTER TABLE aigcspace.models ADD COLUMN IF NOT EXISTS base_url VARCHAR(500) NULL;
  15. COMMENT ON COLUMN aigcspace.models.base_url IS '本地模型API地址';
  16. -- 添加local_api_key字段:存储加密后的本地模型访问密钥
  17. ALTER TABLE aigcspace.models ADD COLUMN IF NOT EXISTS local_api_key VARCHAR(500) NULL;
  18. COMMENT ON COLUMN aigcspace.models.local_api_key IS '本地模型访问密钥(AES加密)';
  19. -- 创建索引:优化本地模型查询
  20. CREATE INDEX IF NOT EXISTS idx_models_is_local ON aigcspace.models(is_local);
  21. CREATE INDEX IF NOT EXISTS idx_models_user_id ON aigcspace.models(user_id);
  22. -- ============================================
  23. -- 回滚迁移: 删除字段和索引
  24. -- ============================================
  25. -- DROP INDEX IF EXISTS aigcspace.idx_models_user_id;
  26. -- DROP INDEX IF EXISTS aigcspace.idx_models_is_local;
  27. -- ALTER TABLE aigcspace.models DROP COLUMN IF EXISTS local_api_key;
  28. -- ALTER TABLE aigcspace.models DROP COLUMN IF EXISTS base_url;
  29. -- ALTER TABLE aigcspace.models DROP COLUMN IF EXISTS user_id;
  30. -- ALTER TABLE aigcspace.models DROP COLUMN IF EXISTS is_local;