I was inspecting the production's data from July 10 2024 and took note of significantly high id numbers in the TestPlanVersion table. The latest row's id is 163615 but there is just 103 rows in the table, which uses auto-increment IDs. Running select currval(pg_get_serial_sequence('"TestPlanVersion"', 'id')) also gives 175465.
The amount of test plan versions that could be imported is 35 and the cronjob responsible for doing that should run every 15 minutes . So potentially, the incremented value is unnecessarily bumped 140 times per hour (105 at a minimum) if there are no new test plan versions.
So this PR does the following:
Resets nextval if it hasn't been used due to that non-unique data condition (continued using nextval for the evaluation of the reset value because currval or lastval may not successfully run if nextval hasn't been ran during the db's transaction session)
Resets nextval to current latest ID + 1 in a migration
I was inspecting the production's data from July 10 2024 and took note of significantly high id numbers in the
TestPlanVersion
table. The latest row's id is163615
but there is just 103 rows in the table, which uses auto-increment IDs. Runningselect currval(pg_get_serial_sequence('"TestPlanVersion"', 'id'))
also gives175465
.This happens because the
import-tests
script is dependent on knowing the "next" id to create relevant data that is retrieved using postgres' nextval (which also also updates the next possible ID value). The issue with this is that those ids could go unused if a potential TestPlanVersion being created is "discarded" if non-unique data is found, but the incremented value is left as is.The amount of test plan versions that could be imported is 35 and the cronjob responsible for doing that should run every 15 minutes . So potentially, the incremented value is unnecessarily bumped 140 times per hour (105 at a minimum) if there are no new test plan versions.
So this PR does the following:
nextval
if it hasn't been used due to that non-unique data condition (continued usingnextval
for the evaluation of the reset value becausecurrval
orlastval
may not successfully run ifnextval
hasn't been ran during the db's transaction session)nextval
to current latest ID + 1 in a migration