I have a table, where I store images and I want to assign each image a consecutive frame number. When I add the images to the database table, it is easy to add it with a frame number that is higher than the last frame number I inserted (because I cache the last number). But when I remove images, I want to update the frame number so that there aren't any "holes" in the frame number and I haven't found a way yet to do this without doing an N+1 query.
The table structure is (simplified):
id | filename | frame_number
---+-------------------+-------------
1 | image1.jpg | 0
2 | image2.jpg | 1
3 | another_image.jpg | 2
Most searched lead to people wanting to create a new (autoincrement) index without holes and people saying that they shouldn't do that or have to create a new table.
I am using python and handle my database with peewee, but that shouldn't make any difference, as I think the thing I want to do could be done in a raw sqlite query.