Repository navigation
Is it safe to un-delete the raw heart-rate samples that the dense-intraday fold soft-deleted? #1111
|
This is a question, not a bug report. I am not asking for a change. I would like to know whether something I am considering on my own instance is safe, before I run it. The questionIs it safe to un-delete ( Context
What I tested (on a copy, not on the live database)
begin;
update measurements
set deleted_at = null, updated_at = now()
where source = 'APPLE_HEALTH'
and type in ('PULSE','HEART_RATE_VARIABILITY','OXYGEN_SATURATION')
and external_id like 'sample:%' and deleted_at is not null;
update measurements
set deleted_at = now(), updated_at = now()
where source = 'APPLE_HEALTH'
and type in ('PULSE','HEART_RATE_VARIABILITY','OXYGEN_SATURATION')
and external_id like 'stats:%' and external_id ~ 'T[0-9]{2}$' and deleted_at is null;
commit;It took about four to five minutes on a small container. What I would like to know
State of my instance right nowNothing from the statement above has been run on the live database. I hold a verified backup (checksummed) and have |
Replies: 1 comment
|
Thanks for asking before running it, and for testing on a copy first. I went through each point in the code and then reproduced the whole sequence on a test database (fold, your swap, rollup rebuild, fold switched back on, purge), and checked the current iPhone app build for the sync questions, so the answers below are observed, not just read. Short answer: yes, it is safe, with four changes to what you posted. 1. Narrow the un-delete to the fold's own tombstones. 2. Bump 3. Rebuild the rollups afterwards. The fold recomputes the DAY bucket from the raw rows before it runs, which is why your DAY counts match. WEEK, MONTH and YEAR are rebuilt afterwards from whatever is live, so today they are means of the hourly rows; in the reproduction a day with a workout hour read 91 bpm at the week level against 137 at the day level. After the swap, run 4. Keep To your other questions:
There is no supported route for this today, only SQL. A setting that keeps raw rows (the switch you already use does that from now on) plus an admin action to restore folded samples for a date range would be worth having. If you'd like to send that as a PR, I'd welcome it; it would also take care of points 1 to 3 for whoever needs this next. |
Thanks for asking before running it, and for testing on a copy first. I went through each point in the code and then reproduced the whole sequence on a test database (fold, your swap, rollup rebuild, fold switched back on, purge), and checked the current iPhone app build for the sync questions, so the answers below are observed, not just read.
Short answer: yes, it is safe, with four changes to what you posted.
1. Narrow the un-delete to the fold's own tombstones.
external_id like 'sample:%'also matches samples deleted for other reasons: by you, by a delete-by-source, or by a cross-source dedup. In the reproduction, a reading I had deleted by hand before the fold came back with the rest …