fix: BUG-20 clamp trips sequence after recompute + renumber migration

This commit is contained in:
Mathieu Moran
2026-08-14 21:45:26 -04:00
parent 25f57603c6
commit 01c7fdf0c4
5 changed files with 52 additions and 0 deletions
+7
View File
@@ -509,6 +509,13 @@ def compute_trips_for_device(device_id):
""",
{"device_id": device_id, **t},
)
# BIGSERIAL consumes a sequence value on every INSERT attempt, even when
# the ON CONFLICT (DO UPDATE) path is taken. Clamp the sequence back to the
# real max id so trip IDs don't inflate by trip_count on every recompute.
cur.execute(
"SELECT setval(pg_get_serial_sequence('trips','id'), "
"(SELECT COALESCE(MAX(id), 0) FROM trips))"
)
return len(trips)