mirror of
https://github.com/yangjian102621/geekai.git
synced 2026-04-22 11:04:26 +08:00
重命名数据表
This commit is contained in:
@@ -11,6 +11,7 @@ package types
|
||||
type ModerationConfig struct {
|
||||
Enable bool `json:"enable"` // 是否启用文本审查
|
||||
Active string `json:"active"`
|
||||
EnableGuide bool `json:"enable_guide"` // 是否启用模型引导提示词
|
||||
GuidePrompt string `json:"guide_prompt"` // 模型引导提示词
|
||||
Gitee ModerationGiteeConfig `json:"gitee"`
|
||||
Baidu ModerationBaiduConfig `json:"baidu"`
|
||||
|
||||
@@ -9,7 +9,6 @@ package handler
|
||||
|
||||
import (
|
||||
"geekai/core"
|
||||
"geekai/core/middleware"
|
||||
"geekai/store/model"
|
||||
"geekai/store/vo"
|
||||
"geekai/utils"
|
||||
@@ -30,12 +29,7 @@ func NewProductHandler(app *core.AppServer, db *gorm.DB) *ProductHandler {
|
||||
// RegisterRoutes 注册路由
|
||||
func (h *ProductHandler) RegisterRoutes() {
|
||||
group := h.App.Engine.Group("/api/product/")
|
||||
|
||||
// 需要用户授权的接口
|
||||
group.Use(middleware.UserAuthMiddleware(h.App.Config.Session.SecretKey, h.App.Redis))
|
||||
{
|
||||
group.GET("list", h.List)
|
||||
}
|
||||
group.GET("list", h.List)
|
||||
}
|
||||
|
||||
// List 模型列表
|
||||
|
||||
@@ -51,6 +51,7 @@ func (s *MigrationService) StartMigrate() {
|
||||
s.MigrateConfig(s.appConfig)
|
||||
s.TableMigration()
|
||||
s.MigrateLicense()
|
||||
s.TableRename()
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -168,6 +169,63 @@ func (s *MigrationService) TableMigration() {
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历所有的数据表,如果表名中包含 chatgpt_,则重命名为 geekai_,只执行一次
|
||||
func (s *MigrationService) TableRename() {
|
||||
key := "migrate:table_rename"
|
||||
if s.redisClient.Get(context.Background(), key).Val() == "1" {
|
||||
logger.Info("数据表重命名已执行,跳过重命名")
|
||||
return
|
||||
}
|
||||
|
||||
logger.Info("开始重命名数据表...")
|
||||
|
||||
// 定义需要重命名的表映射
|
||||
tableRenames := map[string]string{
|
||||
"chatgpt_users": "geekai_users",
|
||||
"chatgpt_orders": "geekai_orders",
|
||||
"chatgpt_products": "geekai_products",
|
||||
"chatgpt_configs": "geekai_configs",
|
||||
"chatgpt_sd_jobs": "geekai_sd_jobs",
|
||||
"chatgpt_mj_jobs": "geekai_mj_jobs",
|
||||
"chatgpt_suno_jobs": "geekai_suno_jobs",
|
||||
"chatgpt_dall_jobs": "geekai_dall_jobs",
|
||||
"chatgpt_video_jobs": "geekai_video_jobs",
|
||||
"chatgpt_jimeng_jobs": "geekai_jimeng_jobs",
|
||||
"chatgpt_files": "geekai_files",
|
||||
"chatgpt_menus": "geekai_menus",
|
||||
"chatgpt_functions": "geekai_functions",
|
||||
"chatgpt_invite_codes": "geekai_invite_codes",
|
||||
"chatgpt_invite_logs": "geekai_invite_logs",
|
||||
"chatgpt_redeems": "geekai_redeems",
|
||||
"chatgpt_power_logs": "geekai_power_logs",
|
||||
"chatgpt_user_login_logs": "geekai_user_login_logs",
|
||||
}
|
||||
|
||||
// 执行重命名操作
|
||||
for oldTableName, newTableName := range tableRenames {
|
||||
// 检查旧表是否存在
|
||||
if s.db.Migrator().HasTable(oldTableName) {
|
||||
// 检查新表是否已存在
|
||||
if !s.db.Migrator().HasTable(newTableName) {
|
||||
err := s.db.Exec(fmt.Sprintf("ALTER TABLE %s RENAME TO %s", oldTableName, newTableName)).Error
|
||||
if err != nil {
|
||||
logger.Errorf("重命名数据表 %s 到 %s 失败: %v", oldTableName, newTableName, err)
|
||||
} else {
|
||||
logger.Infof("成功重命名数据表: %s -> %s", oldTableName, newTableName)
|
||||
}
|
||||
} else {
|
||||
logger.Infof("目标表 %s 已存在,跳过重命名 %s", newTableName, oldTableName)
|
||||
}
|
||||
} else {
|
||||
logger.Infof("源表 %s 不存在,跳过重命名", oldTableName)
|
||||
}
|
||||
}
|
||||
|
||||
// 标记重命名已完成
|
||||
s.redisClient.Set(context.Background(), key, "1", 0)
|
||||
logger.Info("数据表重命名完成")
|
||||
}
|
||||
|
||||
// 迁移配置数据
|
||||
func (s *MigrationService) MigrateConfig(config *types.AppConfig) error {
|
||||
|
||||
|
||||
@@ -5,18 +5,18 @@ import (
|
||||
)
|
||||
|
||||
type AdminUser struct {
|
||||
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||||
Username string `gorm:"column:username;type:varchar(30);uniqueIndex;not null;comment:用户名" json:"username"`
|
||||
Password string `gorm:"column:password;type:char(64);not null;comment:密码" json:"password"`
|
||||
Salt string `gorm:"column:salt;type:char(12);not null;comment:密码盐" json:"salt"`
|
||||
Status bool `gorm:"column:status;type:tinyint(1);not null;comment:当前状态" json:"status"`
|
||||
LastLoginAt int64 `gorm:"column:last_login_at;type:int;not null;comment:最后登录时间" json:"last_login_at"`
|
||||
LastLoginIp string `gorm:"column:last_login_ip;type:char(16);not null;comment:最后登录 IP" json:"last_login_ip"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime;not null;comment:更新时间" json:"updated_at"`
|
||||
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||||
Username string `gorm:"column:username;type:varchar(30);uniqueIndex;not null;comment:用户名" json:"username"`
|
||||
Password string `gorm:"column:password;type:char(64);not null;comment:密码" json:"password"`
|
||||
Salt string `gorm:"column:salt;type:char(12);not null;comment:密码盐" json:"salt"`
|
||||
Status bool `gorm:"column:status;type:tinyint(1);not null;comment:当前状态" json:"status"`
|
||||
LastLoginAt int64 `gorm:"column:last_login_at;type:int;not null;comment:最后登录时间" json:"last_login_at"`
|
||||
LastLoginIp string `gorm:"column:last_login_ip;type:char(16);not null;comment:最后登录 IP" json:"last_login_ip"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null;comment:创建时间" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime;not null;comment:更新时间" json:"updated_at"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (m *AdminUser) TableName() string {
|
||||
return "chatgpt_admin_users"
|
||||
return "geekai_admin_users"
|
||||
}
|
||||
|
||||
@@ -6,13 +6,13 @@ import (
|
||||
|
||||
// ApiKey OpenAI API 模型
|
||||
type ApiKey struct {
|
||||
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||||
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||||
Name string `gorm:"column:name;type:varchar(30);comment:名称" json:"name"`
|
||||
Value string `gorm:"column:value;type:varchar(255);not null;comment:API KEY value" json:"value"`
|
||||
Type string `gorm:"column:type;type:varchar(10);default:chat;not null;comment:用途(chat=>聊天,img=>图片)" json:"type"`
|
||||
LastUsedAt int64 `gorm:"column:last_used_at;type:int;not null;comment:最后使用时间" json:"last_used_at"`
|
||||
LastUsedAt int64 `gorm:"column:last_used_at;type:int;not null;comment:最后使用时间" json:"last_used_at"`
|
||||
ApiURL string `gorm:"column:api_url;type:varchar(255);comment:API 地址" json:"api_url"`
|
||||
Enabled bool `gorm:"column:enabled;type:tinyint(1);comment:是否启用" json:"enabled"`
|
||||
Enabled bool `gorm:"column:enabled;type:tinyint(1);comment:是否启用" json:"enabled"`
|
||||
ProxyURL string `gorm:"column:proxy_url;type:varchar(100);comment:代理地址" json:"proxy_url"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:datetime;not null" json:"updated_at"`
|
||||
@@ -20,5 +20,5 @@ type ApiKey struct {
|
||||
|
||||
// TableName 表名
|
||||
func (m *ApiKey) TableName() string {
|
||||
return "chatgpt_api_keys"
|
||||
return "geekai_api_keys"
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@ package model
|
||||
import "time"
|
||||
|
||||
type AppType struct {
|
||||
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||||
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||||
Name string `gorm:"column:name;type:varchar(50);not null;comment:名称" json:"name"`
|
||||
Icon string `gorm:"column:icon;type:varchar(255);not null;comment:图标URL" json:"icon"`
|
||||
SortNum int `gorm:"column:sort_num;type:tinyint;not null;comment:排序" json:"sort_num"`
|
||||
Enabled bool `gorm:"column:enabled;type:tinyint(1);not null;comment:是否启用" json:"enabled"`
|
||||
Enabled bool `gorm:"column:enabled;type:tinyint(1);not null;comment:是否启用" json:"enabled"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null" json:"created_at"`
|
||||
}
|
||||
|
||||
// TableName 表名
|
||||
func (m *AppType) TableName() string {
|
||||
return "chatgpt_app_types"
|
||||
return "geekai_app_types"
|
||||
}
|
||||
|
||||
@@ -20,5 +20,5 @@ type ChatApp struct {
|
||||
}
|
||||
|
||||
func (m *ChatApp) TableName() string {
|
||||
return "chatgpt_chat_roles"
|
||||
return "geekai_chat_roles"
|
||||
}
|
||||
|
||||
@@ -17,5 +17,5 @@ type ChatItem struct {
|
||||
}
|
||||
|
||||
func (m *ChatItem) TableName() string {
|
||||
return "chatgpt_chat_items"
|
||||
return "geekai_chat_items"
|
||||
}
|
||||
|
||||
@@ -21,5 +21,5 @@ type ChatMessage struct {
|
||||
}
|
||||
|
||||
func (m *ChatMessage) TableName() string {
|
||||
return "chatgpt_chat_history"
|
||||
return "geekai_chat_history"
|
||||
}
|
||||
|
||||
@@ -25,5 +25,5 @@ type ChatModel struct {
|
||||
}
|
||||
|
||||
func (m *ChatModel) TableName() string {
|
||||
return "chatgpt_chat_models"
|
||||
return "geekai_chat_models"
|
||||
}
|
||||
|
||||
@@ -7,5 +7,5 @@ type Config struct {
|
||||
}
|
||||
|
||||
func (m *Config) TableName() string {
|
||||
return "chatgpt_configs"
|
||||
return "geekai_configs"
|
||||
}
|
||||
|
||||
@@ -17,5 +17,5 @@ type DallJob struct {
|
||||
}
|
||||
|
||||
func (m *DallJob) TableName() string {
|
||||
return "chatgpt_dall_jobs"
|
||||
return "geekai_dall_jobs"
|
||||
}
|
||||
|
||||
@@ -14,5 +14,5 @@ type File struct {
|
||||
}
|
||||
|
||||
func (m *File) TableName() string {
|
||||
return "chatgpt_files"
|
||||
return "geekai_files"
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package model
|
||||
|
||||
type Function struct {
|
||||
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||||
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||||
Name string `gorm:"column:name;type:varchar(30);uniqueIndex;not null;comment:函数名称" json:"name"`
|
||||
Label string `gorm:"column:label;type:varchar(30);comment:函数标签" json:"label"`
|
||||
Description string `gorm:"column:description;type:varchar(255);comment:函数描述" json:"description"`
|
||||
Parameters string `gorm:"column:parameters;type:text;comment:函数参数(JSON)" json:"parameters"`
|
||||
Token string `gorm:"column:token;type:varchar(255);comment:API授权token" json:"token"`
|
||||
Action string `gorm:"column:action;type:varchar(255);comment:函数处理 API" json:"action"`
|
||||
Enabled bool `gorm:"column:enabled;type:tinyint(1);not null;default:0;comment:是否启用" json:"enabled"`
|
||||
Enabled bool `gorm:"column:enabled;type:tinyint(1);not null;default:0;comment:是否启用" json:"enabled"`
|
||||
}
|
||||
|
||||
func (m *Function) TableName() string {
|
||||
return "chatgpt_functions"
|
||||
return "geekai_functions"
|
||||
}
|
||||
|
||||
@@ -12,5 +12,5 @@ type InviteCode struct {
|
||||
}
|
||||
|
||||
func (m *InviteCode) TableName() string {
|
||||
return "chatgpt_invite_codes"
|
||||
return "geekai_invite_codes"
|
||||
}
|
||||
|
||||
@@ -15,5 +15,5 @@ type InviteLog struct {
|
||||
}
|
||||
|
||||
func (m *InviteLog) TableName() string {
|
||||
return "chatgpt_invite_logs"
|
||||
return "geekai_invite_logs"
|
||||
}
|
||||
|
||||
@@ -51,5 +51,5 @@ const (
|
||||
|
||||
// TableName 返回数据表名称
|
||||
func (JimengJob) TableName() string {
|
||||
return "chatgpt_jimeng_jobs"
|
||||
return "geekai_jimeng_jobs"
|
||||
}
|
||||
|
||||
@@ -2,14 +2,14 @@ package model
|
||||
|
||||
// Menu 系统菜单
|
||||
type Menu struct {
|
||||
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||||
Name string `gorm:"column:name;type:varchar(30);not null;comment:菜单名称" json:"name"`
|
||||
Icon string `gorm:"column:icon;type:varchar(150);not null;comment:菜单图标" json:"icon"`
|
||||
URL string `gorm:"column:url;type:varchar(100);not null;comment:地址" json:"url"`
|
||||
SortNum int `gorm:"column:sort_num;type:smallint;not null;comment:排序" json:"sort_num"`
|
||||
Enabled bool `gorm:"column:enabled;type:tinyint(1);not null;comment:是否启用" json:"enabled"`
|
||||
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||||
Name string `gorm:"column:name;type:varchar(30);not null;comment:菜单名称" json:"name"`
|
||||
Icon string `gorm:"column:icon;type:varchar(150);not null;comment:菜单图标" json:"icon"`
|
||||
URL string `gorm:"column:url;type:varchar(100);not null;comment:地址" json:"url"`
|
||||
SortNum int `gorm:"column:sort_num;type:smallint;not null;comment:排序" json:"sort_num"`
|
||||
Enabled bool `gorm:"column:enabled;type:tinyint(1);not null;comment:是否启用" json:"enabled"`
|
||||
}
|
||||
|
||||
func (m *Menu) TableName() string {
|
||||
return "chatgpt_menus"
|
||||
return "geekai_menus"
|
||||
}
|
||||
|
||||
@@ -24,5 +24,5 @@ type MidJourneyJob struct {
|
||||
}
|
||||
|
||||
func (m *MidJourneyJob) TableName() string {
|
||||
return "chatgpt_mj_jobs"
|
||||
return "geekai_mj_jobs"
|
||||
}
|
||||
|
||||
16
api/store/model/moderation.go
Normal file
16
api/store/model/moderation.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type Moderation struct {
|
||||
Id uint `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
||||
UserId uint `gorm:"column:user_id;type:int(11);not null;comment:用户ID" json:"user_id"`
|
||||
Input string `gorm:"column:prompt;type:text;not null;comment:用户输入" json:"input"`
|
||||
Output string `gorm:"column:output;type:text;not null;comment:AI 输出" json:"output"`
|
||||
Result string `gorm:"column:result;type:text;not null;comment:鉴别结果" json:"result"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:datetime;not null" json:"created_at"`
|
||||
}
|
||||
|
||||
func (m *Moderation) TableName() string {
|
||||
return "geekai_moderation"
|
||||
}
|
||||
@@ -26,5 +26,5 @@ type Order struct {
|
||||
}
|
||||
|
||||
func (m *Order) TableName() string {
|
||||
return "chatgpt_orders"
|
||||
return "geekai_orders"
|
||||
}
|
||||
|
||||
@@ -20,5 +20,5 @@ type PowerLog struct {
|
||||
}
|
||||
|
||||
func (m *PowerLog) TableName() string {
|
||||
return "chatgpt_power_logs"
|
||||
return "geekai_power_logs"
|
||||
}
|
||||
|
||||
@@ -18,5 +18,5 @@ type Product struct {
|
||||
}
|
||||
|
||||
func (m *Product) TableName() string {
|
||||
return "chatgpt_products"
|
||||
return "geekai_products"
|
||||
}
|
||||
|
||||
@@ -16,5 +16,5 @@ type Redeem struct {
|
||||
}
|
||||
|
||||
func (m *Redeem) TableName() string {
|
||||
return "chatgpt_redeems"
|
||||
return "geekai_redeems"
|
||||
}
|
||||
|
||||
@@ -19,5 +19,5 @@ type SdJob struct {
|
||||
}
|
||||
|
||||
func (m *SdJob) TableName() string {
|
||||
return "chatgpt_sd_jobs"
|
||||
return "geekai_sd_jobs"
|
||||
}
|
||||
|
||||
@@ -31,5 +31,5 @@ type SunoJob struct {
|
||||
}
|
||||
|
||||
func (m *SunoJob) TableName() string {
|
||||
return "chatgpt_suno_jobs"
|
||||
return "geekai_suno_jobs"
|
||||
}
|
||||
|
||||
@@ -29,5 +29,5 @@ type User struct {
|
||||
}
|
||||
|
||||
func (m *User) TableName() string {
|
||||
return "chatgpt_users"
|
||||
return "geekai_users"
|
||||
}
|
||||
|
||||
@@ -15,5 +15,5 @@ type UserLoginLog struct {
|
||||
}
|
||||
|
||||
func (m *UserLoginLog) TableName() string {
|
||||
return "chatgpt_user_login_logs"
|
||||
return "geekai_user_login_logs"
|
||||
}
|
||||
|
||||
@@ -23,5 +23,5 @@ type VideoJob struct {
|
||||
}
|
||||
|
||||
func (m *VideoJob) TableName() string {
|
||||
return "chatgpt_video_jobs"
|
||||
return "geekai_video_jobs"
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ func NewGormConfig() *gorm.Config {
|
||||
return &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Warn),
|
||||
NamingStrategy: schema.NamingStrategy{
|
||||
TablePrefix: "chatgpt_", // 设置表前缀
|
||||
SingularTable: false, // 使用单数表名形式
|
||||
TablePrefix: "geekai_", // 设置表前缀
|
||||
SingularTable: false, // 使用单数表名形式
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,11 +72,11 @@
|
||||
</el-tabs>
|
||||
|
||||
<el-form :model="configs" label-position="top" class="py-5">
|
||||
<el-form-item label="启用文本审查">
|
||||
<el-switch v-model="configs.enable" />
|
||||
<el-form-item label="启用模型引导提示词">
|
||||
<el-switch v-model="configs.enable_guide" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item>
|
||||
<el-form-item v-if="configs.enable_guide">
|
||||
<template #label>
|
||||
<span class="mr-2">大模型引导提示词</span>
|
||||
<el-tooltip
|
||||
@@ -96,7 +96,11 @@
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item>
|
||||
<el-form-item label="启用文本审查服务">
|
||||
<el-switch v-model="configs.enable" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item v-if="configs.enable">
|
||||
<template #label>
|
||||
<div class="flex items-center">
|
||||
<span class="mr-2">选择审查服务</span>
|
||||
|
||||
Reference in New Issue
Block a user