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,35 @@
package dbsync
import (
"path/filepath"
"testing"
)
func TestEnsureBindingUpsert(t *testing.T) {
dir := t.TempDir()
st, err := NewFileStore(filepath.Join(dir, "dbsync"))
if err != nil {
t.Fatal(err)
}
b, err := st.EnsureBinding(Binding{
TenantID: 1,
LocalDatabaseID: "local-a",
OnlineDBID: "online-1",
ChannelID: "ch1",
})
if err != nil || b.ID == "" {
t.Fatalf("ensure: %+v err=%v", b, err)
}
b2, err := st.EnsureBinding(Binding{
TenantID: 1,
LocalDatabaseID: "local-a",
OnlineDBID: "online-2",
})
if err != nil || b2.OnlineDBID != "online-2" || b2.ID != b.ID {
t.Fatalf("upsert: %+v err=%v", b2, err)
}
list, err := st.ListBindings(1, "local-a")
if err != nil || len(list) != 1 {
t.Fatalf("list=%d err=%v", len(list), err)
}
}