blogical has asked for the wisdom of the Perl Monks concerning the following question:
Not necessarily perl, but I'm currently headed towards a perlish solution...
I have two databases, one for development and another for production. They do not share the same data. When I make structural changes in development, I need to apply them to production when I update.
As I am unaware of any native MySQL function combination that addresses this specific need I've begun to think about a perlsih solution.
My current solution is to dump the table structure creation sql, apply some alterations to translate CREATE statements into ALTER / CHANGE statements, and apply that as a patch. This has a few limitations- it doesn't drop leftover columns or keys, and it doesn't create missing columns. While this seems to suit my purposes, I thought I would ask around and see if anyone has seen a similar / better solution.
Edit
Here's what I'm using at the moment. YMMV.
#Step 1. Dump/export table creation sql # Note table and field names enclosed in backquotes #Step 2. Run this filter on it to create alter patch #Step 3. Manually add commands to drop keys, drop and create table / f +ield to top of patch. # Note: created tables and fields needn't be accurate, they just n +eed to exist #Step 4. Run this patch on the database while (<>) { s/^\s*CREATE TABLE (`\w+`) \(/ALTER TABLE $1\n/; s/^\s*(`\w+`)/ CHANGE $1 $1/; s/^\s*PRIMARY KEY/ DROP PRIMARY KEY, ADD PRIMARY KEY/; s/^\s*UNIQUE KEY (`\w+`)/ DROP INDEX $1, ADD UNIQUE $1/; s/^\s*KEY (`\w+`)/ DROP INDEX $1, ADD INDEX $1/; s/^\)//; s/ENGINE=(\w+)/ ENGINE=$1,\n/; s/DEFAULT CHARSET=(\w+)/ DEFAULT CHARSET=$1/; s/^\s+(.+?),?\s*$/ $1,\n/; print; }
b.logical
"One is enough. If you are acquainted with the principle, what do you care for the myriad instances and applications?"
- Henry David Thoreau, Walden
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Generating ALTER TABLE code for MySQL
by liz (Monsignor) on Oct 21, 2006 at 09:28 UTC | |
|
Re: Generating ALTER TABLE code for MySQL
by adrianh (Chancellor) on Oct 21, 2006 at 11:05 UTC | |
by soonix (Chancellor) on May 28, 2018 at 09:03 UTC | |
|
Re: Generating ALTER TABLE code for MySQL
by jdtoronto (Prior) on Oct 21, 2006 at 12:13 UTC | |
|
Re: Generating ALTER TABLE code for MySQL
by Cabrion (Friar) on Oct 21, 2006 at 12:49 UTC | |
|
Re: Generating ALTER TABLE code for MySQL
by badaiaqrandista (Pilgrim) on Oct 22, 2006 at 09:02 UTC |