Files
HealthLog/prisma/migrations/0477_measurements_ingest_token_index/migration.sql
T
Marc-André Bombeck 8d10e5ab94 feat(measurements): resolve each reading's Apple Health write-back
A reading sent with a measurements:write token keeps its EXTERNAL source
and now points at the token that carried it (measurements.ingest_token_id).
Every stored row answers a server-resolved appleHealthMirror: true for
WITHINGS, IMPORT and MANUAL, the token's choice for EXTERNAL, false
otherwise. The plain list accepts appleHealthMirror=true so a client can
page exactly those rows.

Migration 0476 adds the columns and links existing EXTERNAL readings only
where one measurement token provably sent them; 0477 builds the index
concurrently. Backups carry the link and a restore keeps it only for a
token the account still holds. A guard holds every EXTERNAL writer to
setting the link.
2026-10-23 19:27:52 +02:00

9 lines
495 B
SQL

-- The rows a measurement token carried (#1272): walked by the
-- `measurementMirror` domain of `/api/sync/changes` in id order, and looked up
-- by the foreign key's SET NULL. Built CONCURRENTLY so writes to
-- `measurements` carry on during the build; a concurrent build must be the
-- only statement in its file. Most rows have no token, so the index stays
-- small.
CREATE INDEX CONCURRENTLY IF NOT EXISTS "measurements_ingest_token_id_id_idx"
ON "measurements" ("ingest_token_id", "id");