feat(data): health-domain import/upsert support and CLI hygiene fixes - #333
Merged
Conversation
…h operations Add body-measurement to the canonical data namespace with measured-at natural-key upsert, batch update/delete, and a --replace-existing add path for idempotent scale or external-app sync. CLI numeric input stays a string until the domain service converts it with Decimal(str(value)), and snapshot rows round-trip Decimal columns exactly.
Remove the measured-at note that repeated the --measured-at option help, trim the shared date-range note so it no longer restates the --date option help, and make show examples distinct. Add a help_audit lint that flags exact repeats and verbatim option-text copies within one command screen, wired into pre-commit.
Share one DATE_RANGE_TOGETHER_MESSAGE constant between the CLI date argument resolver, the body-measurement and habit services, and the web routers so the wording cannot drift.
Explain uv tool upgrade for unpinned installs and reinstall with @latest for exact-version pins, in both the English and Simplified Chinese READMEs.
Add a partial unique index on body_measurements.measured_at for active rows, mirroring the menstrual day/factor pattern, and soft-delete pre-existing duplicates in the migration. Make the upsert race-safe: on a concurrent-writer IntegrityError the savepoint rolls back and the winner's record is updated instead of raising.
Add menstrual, menstrual-factor, and sleep to data export/import/batch-* with log_date and name natural-key upserts (both DB-enforced by existing partial unique indexes). Menstrual day snapshots carry factor_names and import resolves them against existing active factors. Health domains now share the same machine-oriented import/export contract as body-measurement.
Catch IntegrityError per row in single-resource imports so duplicate natural keys (for example menstrual log_date or factor name) become row-level failures, and surface bundle-import constraint violations as a clean CLI error instead of a traceback.
Collaborator
Author
|
本轮独立代码审查已完成并在
本地 |
Collaborator
Author
|
修正提交 |
Collaborator
Author
TL;DR已完成其它排重对象的软删横向审计;未发现新的生产代码遗漏。此前修正的通用 natural-key 查询会统一排除 审计结论
新增回归
验证
提交: |
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.
TL;DR
将 body-measurement、menstrual、menstrual-factor 与 sleep 纳入
data export/import/batch-*,为 body measurement 提供按measured_at的幂等 upsert 与add --replace-existing,并通过活动行唯一索引、savepoint 与并发 winner 重试收敛重复写入风险。本轮独立审查进一步修正 active-row 匹配、非法 Decimal、menstrual-factor batch-update 缺失、唯一冲突错误处理、迁移覆盖、help 语义和 uv 升级文档偏差。Closes #332
变更内容
1. 健康域 data namespace 支持
data export/import/batch-update/batch-delete支持 body-measurement、menstrual、menstrual-factor 与 sleep。body-measurement.measured_at、menstrual.log_date、menstrual-factor.name,仅匹配 active row。factor_names,bundle 先写入全部 base row、再恢复关系;单资源导入要求相关 factor 已存在。2. body measurement 幂等性与并发安全
add --replace-existing在相同measured_atactive row 存在时更新,否则新增;省略的可选指标保持不变。IntegrityError转换为行级失败。3. Decimal 与 snapshot 稳健性
Decimal(str(value))恢复 canonical 数值。4. CLI help 与统一校验文案
update --measured-at错误声称“省略时默认为当前时间”的语义。--replace-existing增加 help 示例。5. 文档与测试
uv tool upgrade lifeos-cli;精确 pin 需重新 install@latest,并按需保留 extras。关联
验证
bash ./scripts/doctor.sh通过:lint、mypy、dead-code、943 个非集成测试、77% 覆盖率、pip-audit 与 package build 均通过。uv run python scripts/audit_cli_help.py --check-duplicates在 English 与 Simplified Chinese locale 下均通过。LIFEOS_TEST_DATABASE_URL,PostgreSQL CLI integration 按脚本约定跳过;推送bbeb435后的新一轮 GitHub Actions 6/6 checks 全部通过,包括 Python 3.11–3.14、Default Toolchain 与 PostgreSQL CLI Integration。