From 5c31c43248b6885b9df273ff74c65e1fe68d2eb6 Mon Sep 17 00:00:00 2001 From: Robert Love Date: Wed, 10 Jun 2026 11:44:43 -0400 Subject: [PATCH] fix(weight): delete removes the whole day's readings, not one duplicate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The body-weight log shows one row per date (SelectW uses DISTINCT ON (date)), but a day can hold several raw rows — the bt-scale gateway burst-posts the same reading several times (e.g. 6 rows for 2026-06-07 within 4 seconds) and there is no ingest-side dedup. The old DeleteW removed a single id, so SelectW just surfaced the next duplicate and the value appeared unchanged — "delete didn't work." DeleteW now removes every row sharing the targeted id's date, so the displayed entry actually disappears. Verified against a live-data preview: deleting the 2026-06-07 entry cleared all 6 rows and left other days untouched. No UI change (delete control unchanged), so screenshots are unaffected. No schema change. Co-Authored-By: Claude Opus 4.8 --- internal/store/postgres.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/store/postgres.go b/internal/store/postgres.go index 8362e35..0a9fda5 100644 --- a/internal/store/postgres.go +++ b/internal/store/postgres.go @@ -306,9 +306,18 @@ func (s *PostgresStore) InsertW(w models.BodyWeight) error { return err } +// DeleteW removes the body-weight entry the log shows for the given reading's +// day. The log is day-oriented — SelectW returns one row per date via +// DISTINCT ON — but a single day can hold several raw rows: the bt-scale +// gateway burst-posts the same reading several times and there is no +// ingest-side dedup. Deleting only the targeted id would leave the day's +// duplicates behind, so SelectW would surface the next one and the value would +// appear unchanged ("delete didn't work"). Delete every row sharing that id's +// date so the displayed entry actually disappears. func (s *PostgresStore) DeleteW(id int) error { slog.Debug("db: DeleteW", slog.Int("id", id)) - _, err := s.pool.Exec(context.Background(), "DELETE FROM weight WHERE id = $1", id) + _, err := s.pool.Exec(context.Background(), + "DELETE FROM weight WHERE date = (SELECT date FROM weight WHERE id = $1)", id) return err }