chore: drop idx_channels_key on start

This commit is contained in:
JustSong 2024-03-11 02:24:58 +08:00
parent a45fc7d736
commit a90161cf00
2 changed files with 5 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import "github.com/songquanpeng/one-api/common/helper"
var UsingSQLite = false
var UsingPostgreSQL = false
var UsingMySQL = false
var SQLitePath = "one-api.db"
var SQLiteBusyTimeout = helper.GetOrDefaultEnvInt("SQLITE_BUSY_TIMEOUT", 3000)

View File

@ -56,6 +56,7 @@ func chooseDB() (*gorm.DB, error) {
}
// Use MySQL
logger.SysLog("using MySQL as database")
common.UsingMySQL = true
return gorm.Open(mysql.Open(dsn), &gorm.Config{
PrepareStmt: true, // precompile SQL
})
@ -87,6 +88,9 @@ func InitDB() (err error) {
if !config.IsMasterNode {
return nil
}
if common.UsingMySQL {
_, _ = sqlDB.Exec("DROP INDEX idx_channels_key ON channels;") // TODO: delete this line when most users have upgraded
}
logger.SysLog("database migration started")
err = db.AutoMigrate(&Channel{})
if err != nil {