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,41 @@
package dbsync
import (
"context"
"database/sql"
"time"
)
const (
EntryDrain = "drain"
EntryAgentPush = "agent_push"
EntryRollback = "rollback"
OutcomeApplied = "applied_source"
OutcomeKept = "kept_target"
OutcomeRolled = "rolled_back"
)
// RecordLwwOverride 在 LWW 覆盖或保留目标时写入超管审计(失败忽略,不挡同步)。
func RecordLwwOverride(store *FileStore, o LwwOverride) {
if store == nil {
return
}
_ = store.AddLwwOverride(o)
}
// SnapshotTargetRow 取目标端当前行 JSON无行则空串
func SnapshotTargetRow(ctx context.Context, db *sql.DB, driver Driver, table, pkCol, rowPK string) string {
if db == nil || rowPK == "" {
return ""
}
js, _, err := FetchRowJSON(ctx, db, driver, table, pkCol, rowPK)
if err != nil {
return ""
}
return js
}
// DefaultLwwAuditTTL 默认 90 天。
func DefaultLwwAuditTTL() time.Duration {
return 90 * 24 * time.Hour
}