store: scope GetProfile/UpdateProfile to a user_id
Part of per-user profile isolation: profile rows are no longer a global singleton, so every read/write requires the caller's userID. This also requires scoping ListActivities, ListWorkoutKinds, UpsertActivity, CreateWorkoutKind, GetSyncState, UpdateSyncState, and ResetAllSyncedData to userID, plus updating all related tests in the store package.
This commit is contained in:
@@ -5,23 +5,23 @@ import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// ResetAllSyncedData deletes every synced activity (cascading to its laps,
|
||||
// ResetAllSyncedData deletes every synced activity for userID (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 {
|
||||
func (db *DB) ResetAllSyncedData(ctx context.Context, userID int64) 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, `DELETE FROM activities WHERE user_id = ?`, userID); err != nil {
|
||||
return fmt.Errorf("delete activities for user %d: %w", userID, 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)
|
||||
if _, err := tx.ExecContext(ctx, `UPDATE sync_state SET earliest_synced_date = NULL, backfill_complete = 0 WHERE user_id = ?`, userID); err != nil {
|
||||
return fmt.Errorf("reset sync state for user %d: %w", userID, err)
|
||||
}
|
||||
return tx.Commit()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user