fix: BUG-20 clamp trips sequence after recompute + renumber migration
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user