Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Generating ALTER TABLE code for MySQL

by badaiaqrandista (Pilgrim)
on Oct 22, 2006 at 09:02 UTC ( [id://579841]=note: print w/replies, xml ) Need Help??


in reply to Generating ALTER TABLE code for MySQL

This is how I do it:

  1. Create a table called version in each database, containing only one integer field named version. This table will only ever hold one row containing its version.
  2. Create an sql directory in the source directory tree. This table holds sql files with names like 0.sql, 1.sql, 2.sql, etc. All those files contain valid sql statements to create table, drop table, create column, updates, etc. The file names must be sequentially created. The 0.sql contains the initial schema (usually the output of mysqldump without the data). The other *.sql files usually contain various database modification statements.
  3. Create a script that checks the latest version of the database and applies each sql files with the number higher than the version. Update the version table after applying each sql file.

I actually have the script but it still contains my company's specific code in it. If you don't mind playing around with it to make it work in your situation, I probably can send it to you upon request.

This is basically a primitive database versioning system. I recently added a hook functionality into it, which will be automatically called before or after applying an sql file. If I have time, I'd like to submit it to CPAN. But that's quite a big 'if' considering my current workload.

Hope that helps.

-cheepy-
  • Comment on Re: Generating ALTER TABLE code for MySQL

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://579841]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-23 11:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found