Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Do you know where your variables are?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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


In reply to Generating ALTER TABLE code for MySQL by blogical

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (5)
    As of 2014-04-20 03:40 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (485 votes), past polls