feat: ship loose-offline dbsync (validate, agent push, LWW audit)

Add UUID/FK channel checks, agent whitelist/push APIs, bindings, super-admin LWW audit with rollback, reconcile rate limits, and sync docs. Default customers stay opt-in; company conflict UI is removed.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
whm
2026-07-31 17:54:14 +08:00
parent 632057c857
commit 76cdcd760e
39 changed files with 3302 additions and 199 deletions

View File

@@ -0,0 +1,36 @@
# 数据同步 · 开通说明(管理员)
> 依据:`松离线-dbsync方案-最终版.md`
> **默认客户无感**:未显式开通时,终端保存与自增表行为与现网一致。
## 三分模式(客户端配置,智建通道为表白名单源)
| 模式 | 含义 | 谁改 |
|------|------|------|
| `local_only` | 仅本地,无同步 | 默认之一 |
| `online_primary` | HTTP 双写 / 离线 pending旧路径 | 已配线上 API 且未写 MODE 时兼容升 |
| `local_dbsync` | 松离线 + 表白名单 + 本机 agent | **仅显式配置**,禁止自动升 |
智建控制台「数据同步」配的是**通道 + 表白名单 + 线上 DSN**;是否走 `local_dbsync` 由客户端环境变量决定,平台**不会**替全员切默认。
## 开通步骤(增值)
1. 公司管理员在「数据同步」建通道:`local`(本机 B 描述)+ `remote`(线上 A DSN表白名单须 **UUID TEXT PK** + FK 闭包。
2. 默认方向 **本地 → 线上**,冲突策略 **源端覆盖lww_source**
3. 客户端显式设 `YXD_SYNC_MODE=local_dbsync`,并配置通道 ID / token`同步表约定.md`)。
4. 装本机 sync agent 后变更才会上云;未装 agent**本地可保存**,文案须为「需 agent 才上云」。
5. Binding可选登记 `local_database_id → online_db_id`,见 API `/api/v1/admin/sync/bindings`
## 谁能看什么
| 角色 | 可见 |
|------|------|
| 公司管理员 | 通道配置、对账(同步修复)、统计;**无**冲突台 / LWW 覆盖明细 |
| 平台超级管理员 | LWW 覆盖审计(平台工作台) |
| 未开通终端用户 | **零同步文案**,无强制状态条 |
## 相关文档
- [同步表约定.md](./同步表约定.md)
- [数据同步-迁移手册.md](./数据同步-迁移手册.md)(旧客从 HTTP 双写迁入)
- [数据同步-中间件.md](./数据同步-中间件.md)