diff --git a/internal/bootstrap/db.go b/internal/bootstrap/db.go index f80724ab687..58d5209ba01 100644 --- a/internal/bootstrap/db.go +++ b/internal/bootstrap/db.go @@ -53,9 +53,6 @@ func InitDB() { dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local&tls=%s", database.User, database.Password, database.Host, database.Port, database.Name, database.SSLMode) dB, err = gorm.Open(mysql.Open(dsn), gormConfig) - if err == nil { - dB = dB.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8mb4") - } } case "postgres": { diff --git a/internal/db/db.go b/internal/db/db.go index e836e01c574..1b7acc929c5 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -3,6 +3,7 @@ package db import ( "log" + "github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/model" "gorm.io/gorm" ) @@ -11,7 +12,12 @@ var db *gorm.DB func Init(d *gorm.DB) { db = d - err := db.AutoMigrate(new(model.Storage), new(model.User), new(model.Meta), new(model.SettingItem)) + var err error + if conf.Conf.Database.Type == "mysql" { + err = db.Set("gorm:table_options", "ENGINE=InnoDB CHARSET=utf8mb4").AutoMigrate(new(model.Storage), new(model.User), new(model.Meta), new(model.SettingItem)) + } else { + err = db.AutoMigrate(new(model.Storage), new(model.User), new(model.Meta), new(model.SettingItem)) + } if err != nil { log.Fatalf("failed migrate database: %s", err.Error()) }