From c3a01decd89f743e349d6517fd16e5a87466691d Mon Sep 17 00:00:00 2001 From: CaIon <1808837298@qq.com> Date: Tue, 12 Mar 2024 00:35:12 +0800 Subject: [PATCH] chore: drop idx_channels_key on start --- common/database.go | 1 + model/main.go | 4 ++++ 2 files changed, 5 insertions(+) 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 {