fix: clear default external docs_link, add migration to use in-app /docs page

This commit is contained in:
xiezhouwei 2026-06-22 09:51:45 +08:00
parent 64a4a68a6f
commit 76ac1a1b31
2 changed files with 25 additions and 1 deletions

View File

@ -272,6 +272,8 @@ func migrateDB() error {
if err := migrateTokenModelLimitsToText(); err != nil { if err := migrateTokenModelLimitsToText(); err != nil {
return err return err
} }
// Clear legacy external docs_link so the in-app /docs page is used by default
migrateDocsLinkToDefault()
// GORM AutoMigrate + Postgres: MigrateColumnUnique drops NamingStrategy.UniqueName(table, col) // GORM AutoMigrate + Postgres: MigrateColumnUnique drops NamingStrategy.UniqueName(table, col)
// when the column is UNIQUE in information_schema but the model uses uniqueIndex (field.Unique=false). // when the column is UNIQUE in information_schema but the model uses uniqueIndex (field.Unique=false).
// If the live constraint was created with another name (e.g. Postgres default), DROP uni_* fails (SQLSTATE 42704). // If the live constraint was created with another name (e.g. Postgres default), DROP uni_* fails (SQLSTATE 42704).
@ -583,6 +585,28 @@ func migrateTokenModelLimitsToText() error {
return nil return nil
} }
// migrateDocsLinkToDefault clears any external docs_link saved in DB so the in-app /docs page is used.
// Admins can still re-configure an external link via Settings UI if desired.
func migrateDocsLinkToDefault() {
if DB == nil {
return
}
key := "general_setting.docs_link"
var opt Option
if err := DB.Where("`key` = ?", key).First(&opt).Error; err != nil {
// No existing record or table doesn't exist — nothing to migrate
return
}
if opt.Value == "" {
return
}
if err := DB.Model(&Option{}).Where("`key` = ?", key).Update("value", "").Error; err != nil {
common.SysLog(fmt.Sprintf("migrateDocsLinkToDefault: failed to clear %s: %v", key, err))
return
}
common.SysLog("migrateDocsLinkToDefault: cleared legacy docs_link, now using in-app /docs page")
}
// migrateSubscriptionPlanPriceAmount migrates price_amount column from float/double to decimal(10,6) // migrateSubscriptionPlanPriceAmount migrates price_amount column from float/double to decimal(10,6)
// This is safe to run multiple times - it checks the column type first // This is safe to run multiple times - it checks the column type first
func migrateSubscriptionPlanPriceAmount() { func migrateSubscriptionPlanPriceAmount() {

View File

@ -51,7 +51,7 @@ type GeneralSetting struct {
// 默认配置 // 默认配置
var generalSetting = GeneralSetting{ var generalSetting = GeneralSetting{
DocsLink: "https://docs.newapi.pro", DocsLink: "",
DefaultSiteLanguage: "zh-CN", DefaultSiteLanguage: "zh-CN",
PingIntervalEnabled: false, PingIntervalEnabled: false,
PingIntervalSeconds: 60, PingIntervalSeconds: 60,