chore: drop idx_channels_key on start

This commit is contained in:
CaIon
2024-03-12 00:35:12 +08:00
parent c29680b301
commit c3a01decd8
2 changed files with 5 additions and 0 deletions

View File

@@ -2,5 +2,6 @@ package common
var UsingSQLite = false
var UsingPostgreSQL = false
var UsingMySQL = false
var SQLitePath = "one-api.db?_busy_timeout=5000"

View File

@@ -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 {