Files
watchman/.task/2026-11-18/m04-queries/reviews/review-s1.md
T
unknownandCursor 21cc721fcc feat(queries): 完成 M04 查询定义与版本激活
交付不可变查询版本、保存即生效与激活(D26),并带控制台列表筛选排序与试跑预览;补 RLS 下 current_version_no 回填迁移。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-18 18:32:24 +08:00

33 lines
1.9 KiB
Markdown

# M04 Slice S1 Review Note (coder self-check)
Status: implemented; awaiting independent review (not a review verdict).
## Files created
- `services/watchman/src/watchman/models/query.py` — `QueryDefinition`, `QueryVersion`, `VERSION_CONTENT_COLUMNS`
- `services/watchman/migrations/versions/20261118_0006_query_definitions.py` — revises `20261118_0005`
- `services/watchman/src/watchman/services/query_versions.py` — `forbid_version_content_mutation`, `assert_version_immutable`
- `services/watchman/tests/test_query_versions.py` — 28 tests
## Files changed
- `services/watchman/src/watchman/models/__init__.py` — export new models
## Design notes
- `datasource_id` and `definition_id` FKs are `ON DELETE RESTRICT`; extra index `ix_query_definitions_datasource_id`.
- Both tables: ENABLE + FORCE RLS, `tenant_isolation` policy, full CRUD grant to `watchman_app`.
- `query_versions` has no `updated_at`. Immutability is enforced only by the service helper (frozen: content columns plus `tenant_id`, `definition_id`, `version_no`, `published_at`, `published_by`). It is NOT enforced at DB level because UPDATE is granted per the slice spec; direct SQL/ORM writes bypass the helper. Later slices must route all version writes through the service layer. A DB trigger is a possible hardening for the reviewer to consider.
- `latest_published_version_no` is not FK-linked to `query_versions` (set by publish logic in S3).
## Validation
- `uv run alembic upgrade head` — PASS (to `20261118_0006`); downgrade to `0005` then upgrade again — PASS.
- `uv run pytest tests/test_query_versions.py` — 28 passed.
- `uv run pytest` (full) — 290 passed, 1 pre-existing deprecation warning.
- No real passwords; datasource rows use a placeholder ciphertext and synthetic host/user.
## Scope check
- Only `models/`, `migrations/`, `services/query_versions.py` (explicitly requested), `tests/` touched. No API routes, executor, frontend, M03 circuit changes, or git commits.