feat(federation): enhance bd federation status command (bd-wkumz.5)
Improve the federation status command to show more comprehensive information similar to `git remote -v` with health info: - Show peer URLs alongside peer names - Display pending local changes count (uncommitted) - Test connectivity to each peer (via fetch) - Track and display last sync time in metadata table - Show reachability status with error messages on failure Changes: - cmd/bd/federation.go: Enhanced status output with URLs, connectivity checks, pending changes, and last sync time - internal/storage/dolt/federation.go: Added getLastSyncTime/setLastSyncTime methods using metadata table, record sync time on successful sync Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
committed by
Steve Yegge
parent
b7242a67d1
commit
c3f68caf7a
@@ -118,12 +118,36 @@ func (s *DoltStore) SyncStatus(ctx context.Context, peer string) (*storage.SyncS
|
||||
status.HasConflicts = true
|
||||
}
|
||||
|
||||
// TODO: Track last sync time in metadata
|
||||
status.LastSync = time.Time{} // Zero time indicates never synced
|
||||
// Get last sync time from metadata
|
||||
status.LastSync = s.getLastSyncTime(ctx, peer)
|
||||
|
||||
return status, nil
|
||||
}
|
||||
|
||||
// getLastSyncTime retrieves the last sync time for a peer from metadata.
|
||||
func (s *DoltStore) getLastSyncTime(ctx context.Context, peer string) time.Time {
|
||||
key := "last_sync_" + peer
|
||||
var value string
|
||||
err := s.db.QueryRowContext(ctx, "SELECT value FROM metadata WHERE `key` = ?", key).Scan(&value)
|
||||
if err != nil {
|
||||
return time.Time{}
|
||||
}
|
||||
t, err := time.Parse(time.RFC3339, value)
|
||||
if err != nil {
|
||||
return time.Time{}
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// setLastSyncTime records the last sync time for a peer in metadata.
|
||||
func (s *DoltStore) setLastSyncTime(ctx context.Context, peer string) error {
|
||||
key := "last_sync_" + peer
|
||||
value := time.Now().Format(time.RFC3339)
|
||||
_, err := s.db.ExecContext(ctx,
|
||||
"REPLACE INTO metadata (`key`, value) VALUES (?, ?)", key, value)
|
||||
return err
|
||||
}
|
||||
|
||||
// Sync performs a full bidirectional sync with a peer:
|
||||
// 1. Fetch from peer
|
||||
// 2. Merge peer's changes (handling conflicts per strategy)
|
||||
@@ -195,6 +219,9 @@ func (s *DoltStore) Sync(ctx context.Context, peer string, strategy string) (*Sy
|
||||
result.Pushed = true
|
||||
}
|
||||
|
||||
// Record last sync time
|
||||
_ = s.setLastSyncTime(ctx, peer)
|
||||
|
||||
result.EndTime = time.Now()
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user