Skip to content

fix: stop repeated allow_wallet_overflow column migration on restart - #5616

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
feitianbubu:fix/wallet-overflow-migration
Jun 20, 2026
Merged

fix: stop repeated allow_wallet_overflow column migration on restart#5616
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
feitianbubu:fix/wallet-overflow-migration

Conversation

@feitianbubu

@feitianbubu feitianbubu commented Jun 20, 2026

Copy link
Copy Markdown
Member

⚠️ 提交说明 / PR Notice

当前 bool 类型的列,如果使用 default:true
在 mysql 数据库下每次启动 migrate 都会重复报:
model/main.go:269 [rows:0] ALTER TABLE user_subscriptions MODIFY COLUMN allow_wallet_overflow boolean DEFAULT true
model/main.go:304 [rows:0] ALTER TABLE subscription_plans MODIFY COLUMN allow_wallet_overflow boolean DEFAULT true
因为 mysql 的 bool 默认值存储为 1true 每次都会被识别为不匹配而重新 ALTER。

但如果改成 default:1
又会造成在 postgres 数据库下每次启动 migrate 重复报:
model/main.go:304 [rows:0] ALTER TABLE subscription_plans MODIFY COLUMN allow_wallet_overflow boolean DEFAULT 1

目前无论使用哪种默认值字面量,都无法同时兼容 mysql 和 pg 数据库。
这与 #5361allow_balance_pay)属于同一类问题。

📝 变更描述 / Description

去除 SubscriptionPlan.AllowWalletOverflowUserSubscription.AllowWalletOverflow 两个字段的 gorm:"default:true" 列级默认值,改由业务层决定默认值(SubscriptionPlan.NormalizeDefaults 已将 nil 默认按 true 处理,UserSubscription 创建时也总是从套餐显式快照赋值),从根本上消除 AutoMigrate 每次启动的重复 ALTER,且更符合代码逻辑直觉。

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix)
  • ✨ 新功能 (New feature)
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 描述由人工整理撰写。
  • 非重复提交: 已确认非重复(与 fix: stop repeated allow_balance_pay column migration on restart #5361 字段不同,互不重叠)。
  • Bug fix 说明: 属于真实的启动期重复 DDL 噪音,非设计取舍。
  • 变更理解: 已理解去除列默认值不影响既有业务(空值已在业务层兜底为 true)。
  • 范围聚焦: 本 PR 仅去除上述两处列级默认值。
  • 本地验证: go build ./model 通过;重启后不再出现上述重复 ALTER。
  • 安全合规: 无敏感凭据,符合代码规范。

📸 运行证明 / Proof of Work

修复前,mysql 每次启动重复执行:

[rows:0] ALTER TABLE user_subscriptions MODIFY COLUMN allow_wallet_overflow boolean DEFAULT true
[rows:0] ALTER TABLE subscription_plans MODIFY COLUMN allow_wallet_overflow boolean DEFAULT true

去除 gorm:"default:true" 后,重启不再触发上述 DDL。

Summary by CodeRabbit

  • Refactor
    • Updated wallet overflow configuration handling in subscription plans and user subscriptions.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 047220f6-6739-453c-be66-d1ffda57a9cf

📥 Commits

Reviewing files that changed from the base of the PR and between 0229dc2 and f0ae2f0.

📒 Files selected for processing (1)
  • model/subscription.go

Walkthrough

Removes gorm:"default:true" from AllowWalletOverflow in both SubscriptionPlan and UserSubscription structs in model/subscription.go. JSON tags are unchanged; only the database-level GORM default annotation is dropped.

Changes

Remove GORM default:true from AllowWalletOverflow

Layer / File(s) Summary
Remove GORM default tag from both subscription structs
model/subscription.go
AllowWalletOverflow *bool in SubscriptionPlan and AllowWalletOverflow bool in UserSubscription both drop the gorm:"default:true" tag, retaining only json:"allow_wallet_overflow".

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

A tiny tag removed with care,
No more defaults hiding there,
gorm:"default:true" goodbye,
Two fields now bare beneath the sky,
The rabbit hops and all is fair! 🐇

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically summarizes the main change: removing GORM default configuration to fix repeated database migrations on restart.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Calcium-Ion
Calcium-Ion merged commit dfcb74b into QuantumNous:main Jun 20, 2026
2 checks passed
nsuanningmeng added a commit to nsuanningmeng/LemonHub that referenced this pull request Jun 22, 2026
合并上游 3fcd741..0b7ae4e 共 23 个提交(含 tag v1.0.0-rc.13 / rc.14)。

主要上游内容:
- 仪表盘新增流量 Sankey 流向图(model/usedata_flow.go 等新表/统计)、可交互高亮、敏感数据开关
- DataTable 卡片/表格视图切换、渠道卡片重构、移动端卡片布局
- 模型路由可靠性管理(routing-reliability-section)、渠道敏感信息开关
- 迁移修复:allow_wallet_overflow / allow_balance_pay 重复 ALTER 迁移(QuantumNous#5616 QuantumNous#5361)
- 用量日志按登录类型筛选修复、CN 模型图标、计费历史弹窗分页修复
- CLAUDE.md 新增后端规则:避免 GORM 布尔 default 标签导致重启反复 ALTER

冲突处理(兼容本地白标/性能指标功能):
- 上游将 perf_metrics_setting 从「性能」页迁移至「监控与告警(alerts)」页(MonitoringSettingsSection)。
  采纳上游结构,并把本仓库的成功率阈值/错误码白名单/无数据视为满额(success_rate_green/yellow_threshold、
  error_code_whitelist、no_data_as_full)四项特性一并移植进 MonitoringSettingsSection,保持功能不丢失。
- performance-section.tsx 采用上游版本(perf_metrics 已移出)。
- section-registry.tsx 将上述四项接入 alerts 段 defaultValues。

验证:go build ./... 通过;web/default tsc -b 类型检查通过。
nsuanningmeng added a commit to nsuanningmeng/LemonHub that referenced this pull request Jun 22, 2026
合并后 codex + 多代理审查发现的两处低风险项:

- model/main.go: migrateDBFast() 当前为死代码(仅 migrateDB() 在 InitDB 被调用),
  但它缺少 migrateDB() 的失败即停预检(价格精度、model_limits、用户名唯一放松、
  site_id 回填)。一旦将来被接入启动路径,会在 MySQL 非严格模式下静默截断
  price_amount 等数据。为其补齐与 migrateDB() 一致的有序预检 + site_id 回填,
  消除潜在的无损迁移隐患(防御性,非当前可触发缺陷)。
- service/http_client.go: ValidateRelayTargetURL 注释错误地称 SSRF 防护“默认关闭”,
  实际 fetch_setting.go 默认 EnableSSRFProtection=true。更正注释以免误导。

未在本次改动的审查发现(已在汇报中列出,建议作为后续):
- [中] SSRF DNS-rebinding TOCTOU:ValidateURL 解析校验后 http.Transport 连接时二次解析,
  无 IP pinning(共享 HTTP 客户端层面的既有问题,修复涉及面广,单列跟进)。
- [低] SubscriptionPlan.Enabled 仍带 gorm:"default:true",MySQL 每次重启重复 ALTER
  (上游 QuantumNous#5616/QuantumNous#5361 同类修复遗漏项;改 *bool 影响支付校验等 7 处,单列跟进)。
- [信息] 子站 footer/notice 富文本 XSS 为既有特性(HTML/iframe 嵌入),本次新增
  home_badge/title 字段按文本渲染,安全。

验证:go build ./... 通过;model 迁移用例通过。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants