Overview:
I have a page in my application that allows a user to set the priority of a list of records. These records are essentially tasks or goals that the team will need to complete. The order they are given is determined by the user dragging and dropping them into place. Once the user is done and saves the changes, it loops over the data and updates the records in the database with their respective order.
Issue:
The problem I am now running into is on a separate page at which the user can delete a record that may have a priority assigned to it. Since the saving and calculation of a priority is done on another page, deleting a record causes gaps in the sequence.
Example:
Projects that are prioritized:
A (1)
B (2)
C (3)
D (4)
E (5)
F (6)
G (7)
Project gets deleted from another page / function:
A (1)
B (2)
C (3)
D (4)
F (6)
G (7)
Question:
I need to make some type of function I can run after a record is deleted to "repair/re sync" this number sequence. Essentially the single column priority
needs to be updated and in the example, F
would need to be updated to 5 and G
updated to 6 in order to fix the sequence gap.
What I have tried:
Mostly researching a way to solve for this to be honest. I was thinking of putting all the records into a temp table with an Auto Increment
number and using that to update the priority level but I feel like there is probably a more simple solution and wanted some opinions.