fix: migrate existing channels timeout_ms to 300000

This commit is contained in:
Sakurasan
2026-08-31 17:47:52 +08:00
parent 5cb428bba9
commit c6a4fcfbbc
+4 -1
View File
@@ -16,7 +16,7 @@ import (
// 触发一次 AutoMigrate 并把新版本写入库(SQLite 用 PRAGMA user_version)。
// AutoMigrate 对已有表的列判定不收敛(每次都重建表:CREATE __temp + INSERT SELECT + DROP),
// 大表上一次重建数十秒且每次重启重演,所以之后版本未变就直接跳过。
const schemaVersion = 1
const schemaVersion = 2
// Open 打开数据库连接并自动迁移。
// 开发默认 SQLite(dsn 支持 file:...?_journal_mode=WAL),生产可切 postgres。
@@ -48,6 +48,9 @@ func Open(driver, dsn string) (*gorm.DB, error) {
if err := db.AutoMigrate(AllModels()...); err != nil {
return nil, err
}
// v2: 将已有渠道的超时时间从 120000ms 更新为 300000ms
db.Model(&Channel{}).Where("timeout_ms = ?", 120000).Update("timeout_ms", 300000)
log.Println("store: migrated schema v1 -> v2: updated channel timeout_ms to 300000")
if driver != "postgres" {
setSQLiteVersion(db, schemaVersion)
}