fix: synchronize database schema with gorm

This commit is contained in:
Eric 1549169735@qq.com
2026-08-19 22:48:23 +08:00
parent 1320e30cfb
commit 7526b72c63
3 changed files with 35 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ import (
"time"
"git.iwork-ai.com/xdc/iqudo-top1/internal/config"
"git.iwork-ai.com/xdc/iqudo-top1/internal/model"
"go.uber.org/zap"
"gorm.io/driver/mysql"
"gorm.io/gorm"
@@ -37,6 +38,37 @@ func Open(cfg config.DatabaseConfig, log *zap.Logger) (*gorm.DB, error) {
return db, nil
}
// AutoMigrate synchronizes the application schema from the GORM models.
// GORM only adds missing tables, columns and indexes; it does not drop
// existing columns, which keeps production data safe during application
// upgrades.
func AutoMigrate(db *gorm.DB) error {
return db.AutoMigrate(
&model.Tenant{},
&model.User{},
&model.Role{},
&model.TenantMember{},
&model.Scenario{},
&model.ScenarioField{},
&model.ScenarioRule{},
&model.SOP{},
&model.SOPVersion{},
&model.SOPNode{},
&model.SOPEdge{},
&model.KnowledgeCard{},
&model.KnowledgeCardVersion{},
&model.KnowledgeItem{},
&model.KnowledgeRelation{},
&model.SOPRun{},
&model.SOPRunEvent{},
&model.PublicRunSession{},
&model.SOPFeedback{},
&model.AuditLog{},
&model.MultiTableOutbox{},
&model.RefreshToken{},
)
}
type zapGORMLogger struct {
log *zap.Logger
level gormlogger.LogLevel