Skip to content

feat: 自动更新系统 — 版本化迁移引擎 + updater 模块 + CLI + API#60

Merged
wangzhizhou merged 13 commits into
mainfrom
feature/auto-update
Jul 26, 2026
Merged

feat: 自动更新系统 — 版本化迁移引擎 + updater 模块 + CLI + API#60
wangzhizhou merged 13 commits into
mainfrom
feature/auto-update

Conversation

@wangzhizhou

Copy link
Copy Markdown
Contributor

概述

为 EasyBot 添加完整的自动更新支持,涵盖版本化数据库迁移、二进制自动更新、CLI 命令和 API 端点。

设计文档

变更清单

Phase 1: 版本化迁移引擎

  • core/src/storage/migration.rs — Migration 结构体、SCHEMA_VERSION、双后端迁移
  • SQLite/PostgreSQL 前向迁移 + 回滚支持
  • 向后兼容:自动检测旧 schema 为 v1
  • PostgreSQL 多实例互斥 (pg_advisory_lock)
  • 启动时 schema 版本校验

Phase 2: Updater 核心模块 (7 files)

  • types: UpdateInfo, UpdatePlan, UpdateError, 平台检测, 版本比较
  • precheck: 磁盘空间/权限/Docker/dev/插件兼容性检测
  • github: GitHub Releases API + 缓存 + 速率限制
  • download: 流式下载 + SHA256 校验
  • compact: 备份管理 (二进制+DB+config) + 服务路径更新
  • replace: 原子替换 + 回滚 + 启动验证
  • mod: Updater struct 编排完整流程

Phase 3: CLI 子命令

  • easybot check-update — 版本对比 + 迁移清单 + breaking changes
  • easybot update — 预检→确认→下载→替换→验证 (带自动回滚)
  • easybot rollback — 从备份清单恢复

Phase 4: Release Workflow

  • 自动生成 easybot-version.json (含 schema 版本、migration 信息)
  • 作为 release asset 上传

Phase 5: API 端点

  • GET /api/v1/system/update-check — 版本检查
  • /health 增加 schema_version 字段

测试

  • 新增 12 个集成测试 (版本比较、迁移前/后、备份/恢复)
  • 总计 156 tests, 0 failures

使用方式

Introduce a versioned schema migration system replacing the previous
idempotent CREATE TABLE approach.

Changes:
- New migration.rs module with Migration struct, _schema_version tracking
- SCHEMA_VERSION constant compiled into binary
- Forward migration engine (run_migrations) for both SQLite and PostgreSQL
- Backward migration engine (rollback_to) with reverse SQL support
- pg_advisory_lock for PostgreSQL multi-instance migration safety
- Backward compatibility: auto-detect existing schema as v1
- 5 unit tests covering forward/idempotent/rollback/auto-detect edge cases

Design: docs/other/upgrade-strategy.md
Tasks:  docs/other/auto-update-tasks.md
Phase 4 - Release workflow:
- Add easybot-version.json generation step to release.yml
- Upload version.json as release artifact, include in release assets

Phase 5 - API endpoints:
- New GET /api/v1/system/update-check endpoint returning version info
- OpenAPI registration for update_check path and UpdateCheckResponse
- Add schema_version to health check response
- Permission: ConfigRead for update-check (same as /system)
- Update insta snapshot for health response schema change
Phase 6 - Integration tests:
- Version comparison edge cases (pre-release, invalid, semver)
- Platform detection and asset name generation
- Migration on temp SQLite DB (forward, verify, data insert)
- Migration rollback and re-apply cycle
- Backup manifest file read/write roundtrip

Phase 7 - Documentation:
- CLAUDE.md: Added migration system and updater module docs
- Updated: startup version lock, migration lifecycle, upgrade flow
@github-actions github-actions Bot added documentation Improvements or additions to documentation ci core dependencies api labels Jul 21, 2026
- Task 6.6: GitHub API wiremock tests (4 test cases: latest release,
  rate limit 403, not found 404, checksums parsing)
- Task 6.8: API endpoint test for /api/v1/system/update-check
- Task 7.3: Update user-guide.md with upgrade commands section
- Add #[allow(dead_code)] to cfg-gated functions on non-Unix
- available_space() on Windows (precheck.rs)
- set_executable() on Windows (replace.rs)
fix: address auto-update review issues
@wangzhizhou
wangzhizhou merged commit d0995be into main Jul 26, 2026
16 of 18 checks passed
@wangzhizhou
wangzhizhou deleted the feature/auto-update branch July 26, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api ci core dependencies documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant