refactor(measurements): drop the write-only aggregation columns (migration 0272)

Migration 0263 added three columns beside the Apple Health `stats:*`
authority ladder. Only `aggregation_provenance` is ever read back: the
external-measurement reconciler selects it and refuses a lower-authority write
against a higher-authority canonical row, and the cumulative drain reads it
too. That column stays.

`aggregation_contributor_count` and `aggregation_selected_source_hash` are
written by three call sites and read by none. No select, no raw SQL, no export,
no backup, no API contract, no repair path. The import-time selection keeps its
deterministic tiebreak, which compares an in-memory map key computed per flush
rather than a value read back from the table.

Both are plain nullable scalars with no index, unique, check or foreign key, so
the drop is a catalog-only operation that touches no measured value.
This commit is contained in:
Marc-André Bombeck committed 2026-07-25 15:03:44 +02:00
1 parent a3f1d780e7
commit f8f460bb66
9 files changed
+41 -48

No files matched your search

@@ -114,8 +114,6 @@ describe("external measurement identity reconciliation (real Postgres)", () => {
measuredAt: new Date("2026-07-20T09:00:00.000Z"),
sleepStage: null,
aggregationProvenance: "EXPORT_XML_SOURCE_MAX",
aggregationContributorCount: 2,
aggregationSelectedSourceHash: "xml-source-hash",
},
),
},
@@ -132,8 +130,6 @@ describe("external measurement identity reconciliation (real Postgres)", () => {
externalSourceVersion: "native-v1",
deviceType: "Apple Watch",
aggregationProvenance: "HEALTHKIT_STATISTICS",
aggregationContributorCount: null,
aggregationSelectedSourceHash: null,
}),
},
});
@@ -147,8 +143,6 @@ describe("external measurement identity reconciliation (real Postgres)", () => {
measuredAt: nativeMeasuredAt,
sleepStage: null,
aggregationProvenance: "EXPORT_XML_SOURCE_MAX",
aggregationContributorCount: 2,
aggregationSelectedSourceHash: "xml-source-hash",
}),
{ exactExternalMatch: "update" },
);
@@ -171,8 +165,6 @@ describe("external measurement identity reconciliation (real Postgres)", () => {
externalSourceVersion: "native-v1",
deviceType: "Apple Watch",
aggregationProvenance: "HEALTHKIT_STATISTICS",
aggregationContributorCount: null,
aggregationSelectedSourceHash: null,
});
expect(
await prisma.measurement.findUniqueOrThrow({
@@ -194,8 +186,6 @@ describe("external measurement identity reconciliation (real Postgres)", () => {
externalSourceVersion: "native-v2",
deviceType: "Apple Watch",
aggregationProvenance: "HEALTHKIT_STATISTICS",
aggregationContributorCount: null,
aggregationSelectedSourceHash: null,
}),
{ exactExternalMatch: "update" },
);
@@ -601,8 +601,6 @@ describe("POST /api/measurements/batch (real Postgres)", () => {
expect(stored[0]!.value).toBeCloseTo(5200, 5);
expect(stored[0]).toMatchObject({
aggregationProvenance: "HEALTHKIT_STATISTICS",
aggregationContributorCount: null,
aggregationSelectedSourceHash: null,
syncVersion: 2,
});
});
@@ -1217,7 +1215,6 @@ describe("POST /api/measurements/batch (real Postgres)", () => {
expect(estimated[0]).toMatchObject({
value: 8_526,
aggregationProvenance: "EXPORT_XML_SOURCE_MAX",
aggregationContributorCount: 2,
syncVersion: 1,
});
@@ -1235,8 +1232,6 @@ describe("POST /api/measurements/batch (real Postgres)", () => {
expect(canonical[0]).toMatchObject({
value: 8_600,
aggregationProvenance: "HEALTHKIT_STATISTICS",
aggregationContributorCount: null,
aggregationSelectedSourceHash: null,
syncVersion: 2,
});
});
@@ -1297,7 +1292,6 @@ describe("POST /api/measurements/batch (real Postgres)", () => {
expect(rows[0]).toMatchObject({
value: 8_526,
aggregationProvenance: "EXPORT_XML_SOURCE_MAX",
aggregationContributorCount: 2,
syncVersion: 2,
});
});