feat: add schema fingerprint and Z10d alter; refresh sync coop docs
Ship ensure ADD COLUMN and fingerprint API for Yuheng reconcile, and rewrite §0.2–0.3 cooperation checklist in the联调意见. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -403,6 +403,53 @@ func agentSyncSchemaDescribeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
|
||||
}
|
||||
}
|
||||
|
||||
func agentSyncSchemaFingerprintHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
started := time.Now()
|
||||
reqID := r.Header.Get("X-Request-Id")
|
||||
if !requireDBSync(svcCtx, w) {
|
||||
return
|
||||
}
|
||||
channelID := pathvar.Vars(r)["id"]
|
||||
ch, err := svcCtx.DBSync.Store().GetChannelForTenant(channelID, syncTenantID(r))
|
||||
if err != nil {
|
||||
authx.WriteError(w, http.StatusNotFound, err.Error())
|
||||
return
|
||||
}
|
||||
var req dbsync.FingerprintRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
authx.WriteError(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
if !authorizeUserOnlineDB(svcCtx, w, r, channelID, req.OnlineDBID, "用户自助 schema/fingerprint 须带 online_db_id,且须为本人 Binding") {
|
||||
return
|
||||
}
|
||||
if !authorizeUserSyncChannel(svcCtx, w, r, channelID) {
|
||||
return
|
||||
}
|
||||
res, err := dbsync.FingerprintRemoteTables(r.Context(), ch, req)
|
||||
dur := time.Since(started)
|
||||
if err != nil {
|
||||
logSyncReq(r, "schema/fingerprint", channelID, "", "", "err", err.Error(), dur, reqID)
|
||||
if dbsync.IsRetryable(err) {
|
||||
authx.WriteRetryableError(w, http.StatusServiceUnavailable, err.Error())
|
||||
return
|
||||
}
|
||||
authx.WriteError(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
n := 0
|
||||
if res != nil {
|
||||
n = len(res.Tables)
|
||||
}
|
||||
logSyncReq(r, "schema/fingerprint", channelID, "", "", "ok", "", dur, reqID)
|
||||
auditSync(svcCtx, r, "dbsync.schema_fingerprint", map[string]any{
|
||||
"channel_id": channelID, "n": n, "ms": dur.Milliseconds(), "req_id": reqID,
|
||||
})
|
||||
httpx.OkJson(w, map[string]any{"success": true, "result": res})
|
||||
}
|
||||
}
|
||||
|
||||
func uniqueStringSlice(a, b []string) []string {
|
||||
seen := map[string]struct{}{}
|
||||
var out []string
|
||||
|
||||
Reference in New Issue
Block a user