✨ feat(storage): 搭建 SQLite 日程持久化链路 - #224
Open
HuXiaohui424 wants to merge 2 commits into
Open
Conversation
11 tasks
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
| } // namespace | ||
|
|
||
| SqliteScheduleRepository::SqliteScheduleRepository(SqliteDatabase& database) : database_(database) {} | ||
|
|
There was a problem hiding this comment.
The repository only rejects an empty event, then BindSchedule casts schedule.status to an integer without validating it, while ReadSchedule rejects every value other than the three known enum values. A caller can therefore successfully insert a Schedule containing an invalid enum value, after which FindAll() fails with 数据库中的日程状态无效 and the repository cannot read its own row. Validate the status before insert (and ideally enforce the same invariant in the schema with a CHECK) so invalid domain data cannot be persisted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
结论
本 PR 搭建日程模块最小 SQLite 持久化链路:
ScheduleService -> ScheduleRepository -> SqliteScheduleRepository -> SqliteDatabase/SqliteStatement -> SQLite希望 Reviewer 重点确认:
Refs #225
变更
ScheduleRepository,让ScheduleService可注入持久化实现;SqliteDatabase、SqliteStatement,封装连接、预编译语句、参数绑定和事务入口;SqliteScheduleRepository,跑通日程写入和查询;src/sql,字段映射集中到src/mapping;storage_protocol.h/.cc、StorageTransactionPort及旧协议测试;明确未包含:
架构与兼容
删除通用
StorageTransactionPort,改为日程领域拥有的ScheduleRepository。SQLite Adapter 依赖日程接口,日程业务不依赖 SQLite。SQLite C API 只出现在
sqlite_database.cc;Repository 只使用 Database/Statement 和独立 SQL、Mapper。voicelife_storage_sqlite新增对voicelife_schedule的公开依赖,启用设备端 SQLite 时增加sqlite3私有依赖。主机 CI 增加libsqlite3-dev。未修改现有 Profile。无 Repository 注入时,
ScheduleService仍保留原模拟数据路径,因此原有日程行为和测试保持兼容。验证
./scripts/run_pre_submit_checks.sh证据:
scripts/check_format.sh:通过,17 个 C/C++ 文件符合 clang-format 18;scripts/check_code_size.py:通过,12 个变更源码文件符合规模限制;scripts/run_checks.sh:39 个主机测试、架构检查、双端契约、3 个固件 Profile 配置校验、50 个 Python 测试通过;sqlite_schedule_repository_test:真实.db写入、Service 查询、关闭重连及字段恢复通过;run_pre_submit_checks.sh前述阶段均通过,但 IM Gateway 阶段因本机 Corepack 调用 pnpm 11.12.0、项目要求 pnpm 10.17.1 而失败;风险与回退
当前真实 SQLite 链路只在主机集成测试中启用,设备 Runtime 仍使用 memory。创建冲突检查和写入尚未形成多写者原子操作,当前仅支持文档约束的单连接、单写者模型。
正式启用设备端 SQLite 前,仍需完成 FATFS/WL 挂载、固定 SQLite 组件准备、Runtime 组装、数据库迁移及真机恢复验证。
可通过回退提交
2fbdd42恢复旧协议骨架。本 PR 未启用生产 Profile,也未产生需要回滚的设备数据库格式。