mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-05 19:08:38 +08:00
Fix auto migration issue (#16081)
### What problem does this PR solve? Fix DB migration issue. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -194,6 +194,7 @@ func GetModelProviderManager() *models.ProviderManager {
|
||||
// autoMigrateSafely runs AutoMigrate and ignores duplicate index errors
|
||||
// This handles cases where indexes already exist (e.g., created by Python backend)
|
||||
func autoMigrateSafely(db *gorm.DB, model interface{}) error {
|
||||
//err := db.Debug().AutoMigrate(model) // to print debug info
|
||||
err := db.AutoMigrate(model)
|
||||
if err == nil {
|
||||
return nil
|
||||
@@ -202,27 +203,27 @@ func autoMigrateSafely(db *gorm.DB, model interface{}) error {
|
||||
// Check if error is MySQL duplicate index error (Error 1061)
|
||||
errStr := err.Error()
|
||||
if strings.Contains(errStr, "Error 1061") && strings.Contains(errStr, "Duplicate key name") {
|
||||
common.Info("Index already exists, skipping", zap.String("error", errStr))
|
||||
common.Warn("Index already exists, skipping", zap.String("error", errStr))
|
||||
return nil
|
||||
}
|
||||
|
||||
if strings.Contains(errStr, "Error 1060") && strings.Contains(errStr, "Duplicate column name") {
|
||||
common.Info("Column already exists, skipping", zap.String("error", errStr))
|
||||
common.Warn("Column already exists, skipping", zap.String("error", errStr))
|
||||
return nil
|
||||
}
|
||||
|
||||
if strings.Contains(errStr, "Error 1050") && strings.Contains(errStr, "Table") {
|
||||
common.Info("Table already exists, skipping", zap.String("error", errStr))
|
||||
common.Warn("Table already exists, skipping", zap.String("error", errStr))
|
||||
return nil
|
||||
}
|
||||
|
||||
if strings.Contains(errStr, "Error 1091") && strings.Contains(errStr, "Can't DROP") {
|
||||
common.Info("Index/column already dropped, skipping", zap.String("error", errStr))
|
||||
common.Warn("Index/column already dropped, skipping", zap.String("error", errStr))
|
||||
return nil
|
||||
}
|
||||
|
||||
if strings.Contains(errStr, "Error 1138") && strings.Contains(errStr, "Invalid use of NULL") {
|
||||
common.Info("NULL value in existing rows, skipping migration change", zap.String("error", errStr))
|
||||
common.Warn("NULL value in existing rows, skipping migration change", zap.String("error", errStr))
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ type User struct {
|
||||
AccessToken *string `gorm:"column:access_token;size:255;index" json:"access_token,omitempty"`
|
||||
Nickname string `gorm:"column:nickname;size:100;not null;index" json:"nickname"`
|
||||
Password *string `gorm:"column:password;size:255;index" json:"-"`
|
||||
Email string `gorm:"column:email;size:255;not null;index" json:"email"`
|
||||
Email string `gorm:"column:email;size:255;not null;unique" json:"email"`
|
||||
Avatar *string `gorm:"column:avatar;type:longtext" json:"avatar,omitempty"`
|
||||
Language *string `gorm:"column:language;size:32;index" json:"language,omitempty"`
|
||||
ColorSchema *string `gorm:"column:color_schema;size:32;index" json:"color_schema,omitempty"`
|
||||
|
||||
Reference in New Issue
Block a user