Files
geniusrun/backend/internal/store/reset.go
Christophe Vila 7f7e4b10f0 Merge backfill into Sync now, replace Full backfill with a destructive Reset all
Sync now now runs Backfill (resumes from the watermark, so a widened history
horizon is picked up automatically) then IncrementalSync then detail-fill, in
one click. "Full backfill" is gone -- in its place, "Reset all" (styled as a
destructive action, gated by a confirm dialog) wipes every synced activity
and its laps/kind assignments and rewinds the backfill watermark, so the next
sync performs a genuinely fresh pull instead of trying to patch up existing
rows with newer schema fields.
2026-07-19 12:41:38 +02:00

28 lines
933 B
Go

package store
import (
"context"
"fmt"
)
// ResetAllSyncedData deletes every synced activity (cascading to its laps,
// activity_samples, and kind_assignments via ON DELETE CASCADE) and rewinds
// the backfill watermark to its initial state, so a subsequent Backfill
// starts a genuinely fresh pull instead of thinking history is already
// covered. Workout kinds (the user's taxonomy) are left untouched.
func (db *DB) ResetAllSyncedData(ctx context.Context) error {
tx, err := db.BeginTx(ctx, nil)
if err != nil {
return fmt.Errorf("begin reset tx: %w", err)
}
defer tx.Rollback()
if _, err := tx.ExecContext(ctx, `DELETE FROM activities`); err != nil {
return fmt.Errorf("delete activities: %w", err)
}
if _, err := tx.ExecContext(ctx, `UPDATE sync_state SET earliest_synced_date = NULL, backfill_complete = 0 WHERE id = 1`); err != nil {
return fmt.Errorf("reset sync state: %w", err)
}
return tx.Commit()
}