Skip to content

Commit 53602c0

Browse files
spech66Copilot
andauthored
Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 355a879 commit 53602c0

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

LifelogBb/Migrations/20260515071837_ConfigHeight.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@ protected override void Up(MigrationBuilder migrationBuilder)
1717
nullable: false,
1818
defaultValue: 170);
1919

20-
// Backfill Height from the most recent Weight entry in the same unit-valid range.
20+
// Backfill Height from the most recent Weight entry only when the stored value is
21+
// unambiguous for the current unit system. The valid ranges overlap from 40-98, so
22+
// those values cannot be safely inferred as metric or imperial during migration.
2123
// Range values align with EditConfigViewModel constants: metric 40-250, imperial 16-98.
2224
migrationBuilder.Sql(@"
2325
UPDATE Configs
2426
SET Height = CASE
2527
WHEN UnitsType = 1 THEN COALESCE(
26-
(SELECT Height FROM Weights WHERE Height BETWEEN 16 AND 98 ORDER BY CreatedAt DESC LIMIT 1),
28+
(SELECT Height FROM Weights WHERE Height BETWEEN 16 AND 39 ORDER BY CreatedAt DESC LIMIT 1),
2729
67
2830
)
2931
ELSE COALESCE(
30-
(SELECT Height FROM Weights WHERE Height BETWEEN 40 AND 250 ORDER BY CreatedAt DESC LIMIT 1),
32+
(SELECT Height FROM Weights WHERE Height BETWEEN 99 AND 250 ORDER BY CreatedAt DESC LIMIT 1),
3133
170
3234
)
3335
END

0 commit comments

Comments
 (0)