diff --git a/common/database.go b/common/database.go index c8f59a8d..ce7a9bc1 100644 --- a/common/database.go +++ b/common/database.go @@ -2,5 +2,6 @@ package common var UsingSQLite = false var UsingPostgreSQL = false +var UsingMySQL = false var SQLitePath = "one-api.db?_busy_timeout=5000" diff --git a/model/main.go b/model/main.go index bb91255e..62a02a21 100644 --- a/model/main.go +++ b/model/main.go @@ -62,6 +62,7 @@ func chooseDB() (*gorm.DB, error) { dsn += "?parseTime=true" } } + common.UsingMySQL = true return gorm.Open(mysql.Open(dsn), &gorm.Config{ PrepareStmt: true, // precompile SQL }) @@ -92,6 +93,9 @@ func InitDB() (err error) { if !common.IsMasterNode { return nil } + if common.UsingMySQL { + _, _ = sqlDB.Exec("DROP INDEX idx_channels_key ON channels;") // TODO: delete this line when most users have upgraded + } common.SysLog("database migration started") err = db.AutoMigrate(&Channel{}) if err != nil {