This must mean that you've stored all of the EXIF data from the photo during the initial metadata scan?

That puts a *lot* more data into the database.  And it also requires a complete rescan of all the existing images, which will be a real headache.

I recommend instead that you keep the simple metadata parsing we currently have, and read the full exif medata here, update the orientation and write it back.