🎨 优化角色卡功能模块,后续待优化图像上传&前端流畅性待优化

This commit is contained in:
2026-02-11 05:33:38 +08:00
parent 56e821b222
commit cf3197929e
12 changed files with 576 additions and 198 deletions

View File

@@ -100,6 +100,9 @@ func RegisterTables() {
os.Exit(0)
}
// 修复 PostgreSQL 序列(确保序列值与现有数据一致)
fixPostgresSequences()
// 创建向量索引(必须在 AutoMigrate 之后)
CreateVectorIndexes()
@@ -111,3 +114,27 @@ func RegisterTables() {
}
global.GVA_LOG.Info("register table success")
}
// fixPostgresSequences 修复 PostgreSQL 自增序列与现有数据不一致的问题
// AutoMigrate 后序列可能落后于已有数据的 max(id),导致插入时主键冲突
func fixPostgresSequences() {
if global.GVA_CONFIG.System.DbType != "pgsql" {
return
}
// 需要修复序列的表名列表
tables := []string{
"ai_characters",
"app_users",
"app_user_sessions",
"app_user_favorite_characters",
}
for _, table := range tables {
seqName := table + "_id_seq"
sql := "SELECT setval('" + seqName + "', COALESCE((SELECT MAX(id) FROM " + table + "), 0) + 1, false)"
if err := global.GVA_DB.Exec(sql).Error; err != nil {
global.GVA_LOG.Warn("fix sequence failed", zap.String("table", table), zap.Error(err))
}
}
}