Merge remote-tracking branch 'origin/release/v1.46.0' into feat/v146-ui

# Conflicts:
#	src/__tests__/baselines/source-function-lines.json
#	src/__tests__/baselines/version-stamp-comments.json
This commit is contained in:
Marc-André Bombeck committed 2026-10-23 19:54:08 +02:00
commit 879473305c
115 files changed
+5037 -599

No files matched your search

@@ -66,6 +66,8 @@ export interface MeasurementInsertRow {
sleepStage: string | null;
rhythmClassification: string | null;
deviceType: string | null;
/** The token an EXTERNAL row came from (#1272); null when absent. */
ingestTokenId?: string | null;
syncVersion: number;
deletedAt: Date | null;
createdAt?: Date;
@@ -98,6 +100,7 @@ const COLUMNS: { [K in keyof MeasurementInsertRow]-?: [string, Kind] } = {
sleepStage: ["sleep_stage", "enum:sleep_stage"],
rhythmClassification: ["rhythm_classification", "enum:rhythm_classification"],
deviceType: ["device_type", "text"],
ingestTokenId: ["ingest_token_id", "text"],
syncVersion: ["sync_version", "int4"],
deletedAt: ["deleted_at", "timestamp"],
createdAt: ["created_at", "timestamp"],
@@ -41,6 +41,9 @@ export const measurementSchema = z
sleepStage: z.enum(SleepStage).nullable().optional(),
rhythmClassification: z.enum(RhythmClassification).nullable().optional(),
deviceType: z.string().nullable().optional(),
// The token that carried an EXTERNAL reading (#1272). Kept on restore
// only when the restoring account still holds that token.
ingestTokenId: z.string().max(64).nullable().optional(),
syncVersion: z.number().int().optional(),
deletedAt: isoDateTime.nullable().optional(),
createdAt: isoDateTime.optional(),
+2
View File
@@ -42,6 +42,7 @@ const MEASUREMENT_BACKUP_SELECT = {
sleepStage: true,
rhythmClassification: true,
deviceType: true,
ingestTokenId: true,
syncVersion: true,
deletedAt: true,
createdAt: true,
@@ -86,6 +87,7 @@ function serialiseMeasurement(
sleepStage: measurement.sleepStage,
rhythmClassification: measurement.rhythmClassification,
deviceType: measurement.deviceType,
ingestTokenId: measurement.ingestTokenId,
syncVersion: measurement.syncVersion,
deletedAt: measurement.deletedAt?.toISOString() ?? null,
createdAt: measurement.createdAt.toISOString(),
+25 -4
View File
@@ -156,7 +156,10 @@ export async function clearMeasurementRollups(
await ctx.tx.measurementRollup.deleteMany({ where: { userId: ctx.ownerId } });
}
function toRestoredMeasurementData(measurement: BackupMeasurement) {
function toRestoredMeasurementData(
measurement: BackupMeasurement,
ownTokenIds: ReadonlySet<string>,
) {
return {
type: isLegacyRmssdRow(measurement)
? ("HRV_RMSSD" as const)
@@ -204,6 +207,13 @@ function toRestoredMeasurementData(measurement: BackupMeasurement) {
sleepStage: (measurement.sleepStage ?? null) as never,
rhythmClassification: (measurement.rhythmClassification ?? null) as never,
deviceType: measurement.deviceType ?? null,
// The token link (#1272) survives only onto the account that still holds
// the token: a backup restored elsewhere, or after the token was deleted,
// would point at a row that is not there or not this account's.
ingestTokenId:
measurement.ingestTokenId && ownTokenIds.has(measurement.ingestTokenId)
? measurement.ingestTokenId
: null,
syncVersion: measurement.syncVersion ?? 1,
deletedAt: measurement.deletedAt ? new Date(measurement.deletedAt) : null,
...(measurement.createdAt
@@ -343,8 +353,9 @@ async function reconcileWithoutId(
tx: Prisma.TransactionClient,
ownerId: string,
measurement: BackupMeasurement,
ownTokenIds: ReadonlySet<string>,
): Promise<void> {
const restoredData = toRestoredMeasurementData(measurement);
const restoredData = toRestoredMeasurementData(measurement, ownTokenIds);
const existing = await tx.measurement.findFirst({
where: {
userId: ownerId,
@@ -378,6 +389,16 @@ export async function restoreMeasurements(ctx: RestoreContext): Promise<void> {
const measurementBatchSize = 1_000;
const isExpiredTombstone = await expiredTombstoneFilter(ctx);
const { isShadowedLegacyRmssd } = ctx.measurementPrepass;
// Tokens are not part of a backup; the ones the account holds now decide
// which token links come back.
const ownTokenIds = new Set(
(
await tx.apiToken.findMany({
where: { userId: ownerId },
select: { id: true },
})
).map((token) => token.id),
);
ctx.reportMeasurements(0);
await streamed.forEachMeasurementBatch(
measurementBatchSize,
@@ -395,7 +416,7 @@ export async function restoreMeasurements(ctx: RestoreContext): Promise<void> {
{
id: measurement.id,
userId: ownerId,
...toRestoredMeasurementData(measurement),
...toRestoredMeasurementData(measurement, ownTokenIds),
},
]
: [],
@@ -412,7 +433,7 @@ export async function restoreMeasurements(ctx: RestoreContext): Promise<void> {
}
for (const measurement of batch) {
if (measurement.id) continue;
await reconcileWithoutId(tx, ownerId, measurement);
await reconcileWithoutId(tx, ownerId, measurement, ownTokenIds);
}
},
);