[wp-hackers] Re: Handling upgrades to a plugin's database scheme

Christian Höltje docwhat+list.wp.hackers at gerf.org
Tue Oct 30 20:37:46 GMT 2007

* James Davis (james at freecharity.org.uk) [071030 15:42]:
> I've written a plugin which uses it's own database table to store
> data.  I've since extended the plugin which now uses a slightly
> different schema for that table.
> What's the best way to handle the change in schema when users
> upgrade from the previous version of the plugin to the current one?

This may be overkill for your application, but....

A common pattern is to:
 * You number each schema.
 * You create rules to upgrade from each schema.
 * You store the current schema # in the database someplace.
 * Then you can detect the schema #, and upgrade the database via the

  Your plugin runs and detects schema version 32.  The plugin is
  expecting #38.  You would then run, one after each other, upgrades
  to 33, 34, 35, 36, 37, 38.


If you can't beat them, arrange to have them beaten.
       -- George Carlin

The Doctor What: Need I say more?                http://docwhat.gerf.org/
docwhat *at* gerf *dot* org                                        KF6VNC

More information about the wp-hackers mailing list