[wp-hackers] Table updater wish

Owen Winkler ringmaster at midnightcircus.com
Fri Jul 30 18:45:51 UTC 2004


> This could be something that parses SQL dumps and extracts 
> the info from 
> there. But the idea is for it to be flexible enough that when 
> we add a new 
> column or index or something:
> 
> 1. We only change one place in the code and it's in the 
> install and upgrade 2. It won't add duplicates

The function I have now takes a string (semi-colon separated) or array
of strings as a parameter.  These strings are CREATE TABLE statements
(DDL) that would create a database in a fresh state.  The function
returns an array of strings that you could execute in series on the
existing database that would put it in that state.

If you had a clean WP database, you could dump the creation queries from
phpMyAdmin, modify it where the table names appear (tablename >>
{$wpdb->tablename}), and pass that as a string to my function.  Ergo,
updating the installer/upgrader would take all of 5 minutes.  IE:

$wp_tables = "<tweaked dump from phpMyAdmin>";
foreach(dbUpdate($wp_tables) as $qry) $wpdb->query($qry);

That should work for upgrade as well as fresh install.

As an added bonus, plugin authors could use my function to
update/install their own tables by passing the DDL queries for only
their tables and then looping through the results, as above.

There are limitations to the function, of course.  Like, it doesn't
handle indices on anything other than a fresh table create.  If this is
needed, I could add it.

I'd like to see something like this work.  The function is mostly done,
I just need to run some tests on live WP data, which means ripping apart
the installer/upgrader, which I don't want to do if I've gone astray.

Owen





More information about the hackers mailing list