[SEN] 修复旧设备 capabilities 迁移到 JSONB #92
Closed
opened 2026-08-15 15:08:15 +08:00 by ila
·
3 comments
No Branch/Tag Specified
dev
feat/183-bell-contact-schedule
docs/171-coordination-e2e-wiki
feature/155-coordination-e2e
docs/168-sync-coordination-wiki
feature/154-coordination-deployment
docs/152-153-connectors
feature/153-event-evidence-connector
feature/152-brain-control
docs/151-machine-identity-acceptance
task/151-machine-identity
docs/150-contract-acceptance
docs/148-149-contract-acceptance
feature/149-runtime-status-contract
feature/150-event-evidence-contract
feature/148-source-config-contract
docs/8-mvp-acceptance
feature/145-sense-e2e-isolation-cleanup
feature/134-bell-independent-e2e
feature/142-bell-ui-shell-startup
feature/140-bell-minimal-admin-menu
feature/138-bell-production-captcha
feature/133-bell-alert-lifecycle
feature/132-bell-rule-alert
feature/131-bell-event-receipt
feature/16-brain-local-events
feature/15-brain-rules
feature/14-brain-vision
feature/13-brain-decode
feature/11-brain-input
main
feat/sense-79-ops-alerts
feat/sense-78-outbox
feat/77-sense-media-shards
feat/76-sense-edge-node-status
feat/75-sense-quota-capacity
feature/74-sense-operations
feature/73-sense-local-events
feature/72-sense-bulk-provisioning
feature/113-record-parallel-acceptance
feature/113-sync-parallel-implementation-docs
feature/71-sense-e2e-regression
feature/62-bell-goadmin-skeleton
feature/10-brain-python-cuda-skeleton
feature/108-sync-devharness
feature/90-sense-root-launcher
feature/106-supervisor-sense
fix/101-sense-layout-shell
feature/104-sense-login-30-days
docs/99-acceptance
feature/99-sense-app-config
feature/70-sense-windows-delivery
fix/95-sense-media-path-constraint
feature/97-sense-password-login
docs/92-acceptance
fix/92-sense-capabilities-jsonb
docs/69-acceptance
feature/69-sense-area
feature/68-sense-liveview
feature/67-sense-mediamtx-reconcile
feature/66-sense-onvif-admission
feature/65-sense-device-credential
feature/64-sense-auth-rbac-audit
feature/61-sense-goadmin-source-baseline
docs/acceptance-batch-20260814
coordination/58-finalize-branch-governance
explore
agent/codex/56-sense-device-edit-payload
agent/codex/54-sense-liveview-on-demand
agent/codex/51-sense-auto-liveview
agent/codex/50-sense-split-camera-credentials
agent/codex/48-sense-onvif-digest
agent/codex/46-sense-env-loader
agent/codex/44-sense-empty-navigation
agent/codex/42-sense-password-length-only
agent/codex/40-sense-password-min-6
agent/codex/37-sense-windows-package
agent/codex/36-bell-docs
agent/codex/9-bell-mvp
agent/codex/21-sense-mvp
agent/codex/28-current-prototypes
agent/codex/5-goadmin-baseline
agent/codex/3-go-admin-ui-reuse
agent/codex/1-collaboration-rules
No results found.
Milestone
No items
No Milestone
Projects
Clear projects
No projects
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: ila/yovision#92
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
状态
已完成
基本信息
原始需求与追溯
Sense\start_sense.bat时报告 PostgreSQLSQLSTATE 42804:“字段 capabilities 的默认值不能转换成类型 jsonb”,随后确认“建工单,做”。sense_devices.capabilities为text NOT NULL DEFAULT ''::text,有 1 条旧记录;值不是 JSON,但属于受支持的旧单值能力标识;2026081414000迁移记录为 0。jsonb,GORM AutoMigrate 直接转换既有 text 字段时先被旧默认值阻断;只删除默认值仍会被旧单值数据阻断。目标
让 Sense 设备迁移安全兼容旧
textcapabilities 列,在保留设备记录语义的前提下转换为 JSONB,并让 Windows production 启动迁移可以继续。做什么
sense_devices.capabilities存在且类型不是 json/jsonb 时执行。[],把允许的旧单值转换为 JSON 数组,合法 JSON 数组保持数组。[]默认值,再继续现有 AutoMigrate。不做什么
不删除设备或凭据;不清空数据库;不修改客户配置;不自动备份生产库;不绕过迁移;不修改 Brain、Bell、共享契约或根级部署。
写路径
Sense/server/cmd/migrate/migration/version/2026081414000_device.goSense/server/cmd/migrate/migration/version/2026081414000_device_test.goSense/server/app/sense/device/models/device.go(仅在默认表达式确需调整时)Troubleshootingdocs/06-troubleshooting.mddocs/task/<本工单归档>.mdwiki-docs.json禁止写入:
Brain/**、Bell/**、contracts/**、Sense/dist/**、当前用户数据库数据。已确认方案
兼容逻辑置于现有
2026081414000迁移的事务开头,因为受影响数据库尚未记录该版本,后置新版本无法越过当前失败点。SQL 只对白名单旧值做确定性转换;迁移前要求备份,失败时整个事务回滚。风险与回退
验收标准
text DEFAULT ''列不再触发 SQLSTATE 42804[],合法 JSON 数组保持语义验证方式
go test ./cmd/migrate/migration/version、go test ./...、go vet ./...、go build ./...。git diff --check、Wiki 定向与可行时全量一致性检查。文档影响
更新 PostgreSQL
capabilities兼容迁移原因、备份要求、失败处理和重试方式。实施结果与证据(2026-08-15)
68b436afe3badfaee5f453c4578c、3a686a8fix/92-sense-capabilities-jsonb→dev,保持打开待验收)a169b2323323d9de6304e9b430ddbe9888ea1d25d10479f732597bd90dac4de03edc0cd4b39b6352sense数据库未执行写迁移,当前Sense/dist二进制未替换。check_harness.py --strict仅因既存 #66/#67 归档缺少当前模板章节失败。用户验收与关闭(2026-08-15)
#92 验收通过。dev,merge commit:eaa6ae081542b0b9c74cc2d92a9138639fdbe530。dev,merge commit:40409707cc04fef8d6b51c806246577312c8dd3c。cbdcc65c2b7da74048713d49dcb4b49b47cec17e。开始实施。分支
fix/92-sense-capabilities-jsonb从最新dev创建,工作区初始干净。只读诊断确认旧列为text NOT NULL DEFAULT ''::text,1 条记录为受支持的旧单值但非 JSON,迁移版本未登记。兼容逻辑将在同一迁移事务内先锁表、全量验证,再确定性转换;当前用户数据库不作为测试目标。#92 已完成并进入待验收。
dev,未合并)68b436a、fe3badf、aee5f45、3c4578c、3a686a8sense数据库只做过只读诊断,没有写入。用户已于 2026-08-15 明确验收通过。
dev:eaa6ae081542b0b9c74cc2d92a9138639fdbe530dev:40409707cc04fef8d6b51c806246577312c8dd3ccbdcc65c2b7da74048713d49dcb4b49b47cec17e