in reply to Re: How to synchronize two database tables in MySQL?
in thread How to synchronize two database tables in MySQL?

I'm not really concerned about data right now, just structure. I'll be setting default values for any new columns I might add, but I need everyone to have the same table definitions. Here's how this is currently done:
  1. Examine table structure to determine which version they have
  2. Run different queries depending on the version

What I want to do is store the table format within the install script, which would then examine the database and run the appropriate query, whether it's a DROP or ALTER or CREATE query. In the course of thinking about this, my theoretical structure looks something like this:
my %tables = ('table1' => ( 'column1' => 'column definition', 'column2' => 'column definition') );
with a separate hash for keys and storage engine types.

Replies are listed 'Best First'.
Re^3: How to synchronize two database tables in MySQL?
by davidrw (Prior) on Jan 08, 2006 at 01:55 UTC
    When you do #2, what are the various queries? i.e. are you making a set of queries to bring verion X up to current for all previous versions? If so, would be a lot easier (for this and future releases) if the set queries were to bring version X up to version Y (version X+1), and just apply step #2 iteratively until you're at the current state.

    You could obsolete #1 by starting to store the schema version number in the schema somewhere .. if you already have a config file/table could just put it in there .. or maybe a new table version_history with columns version_number, version_name, version_description, release_date, install_date ...