We'll add the ability to edit and delete lessons from a course's module. When editing, we'll also decrement the order field for all lessons within the module after the lesson being deleted.
Sorry for all the questions. I am getting a lock timeout error when I try to delete. I copied your destroy_lesson code from the repo to make sure our files matched and still get it. I get it trying to delete any lesson. I built my DB fresh and reseeded, just in case. If I remove the await decrement lesson I can delete lessons just fine, just for some reason the lessons are locked when trying to increment:
ERROR (5078): update lessons set order = order - 1 where (`module_id` = 1 and order > 1) and (`organization_id` = 1) - Lock wait timeout exceeded; try restarting transaction.
The query looks right, it seems to be trying to update the right data. Any ideas?
No worries at all! It's been a long while since I've used MySQL, so my platform-specific knowledge here will be limited. But, if it works fine without the decrement then I'd imagine you most likely have a stuck lock or transaction on one of your lessons. Something not directly related to the decrement, but rather blocking the decrement from succeeding.
This may or may not be code-related. It could be a lock added by a client application or CLI using your MySQL table. It could also be another transaction touching one of the lesson rows that was never committed or rolled back. Here is a StackOverflow thread that discussed some query options to dig into what might be locking things up.
I can try and get MySQL set up and test it out this evening after work to ensure it isn't a code issue specific to MySQL.
Alrighty, so I took a look into it. I was also getting the error with MySQL, and it was indeed a code issue! I accidentally missed binding the organization to the transaction, which caused the decrement to run outside the confinement of the transaction - hence the lock block.
Below is the updated code that fixes this issue! Terribly sorry about the miss here! I'll get a note about this added into the lesson.