How to do plugin update related database actions the right way?

I have a plugin that stores information in the WPDB in some format. In newer versions that format may be adjusted or extended.

Currently the plugin saves a database version in the options table. On every page load the plugin checks if the database version is lower than the one it has. If that is the case the plugin fires some update routines that adjust the database format and updates the database version field.

So if the plugin is replaced manually or by the WordPress updater the plugin recognizes the different database version and do the updates.

That works absolutely fine so far and in theory. The problem is that after the plugin is updated all page loads maybe trigger this update routines as long as one of them has finished and the database version field is updated. But if the same routine is fired twice it destroys the database format … At least i think that is the problem.

To update the database version field before the update routines run may help but i want to ask: What is the best practice for doing database related updates savely?

Read more here:: How to do plugin update related database actions the right way?

Leave a Reply

Your email address will not be published. Required fields are marked *