Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Generating ALTER TABLE code for MySQL

by badaiaqrandista (Pilgrim)
on Oct 22, 2006 at 09:02 UTC ( #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.

  • Comment on Re: Generating ALTER TABLE code for MySQL

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://579841]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2018-06-25 16:03 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (127 votes). Check out past polls.