A Weblog written, styled and hacked by Joel Moss
I am excited to announce the a beta of the next version of the popular database Migrations shell for CakePHP 1.2. It’s a little later than expected (I wanted a release candidate out by now) due to a certain muppet who didn’t commit his changes to SVN!
Take a look at the ChangeLog, and you will see a few long needed changes. The most notable being the ones discussed earlier. Here’s the rundown of what you can find in the beta…
Timestamped Migrations
All migration files now use the current GMT timestamp of when they were generated. This has been added to almost eradicate any chance of conflicts when working as part of a team.
Interleaved Migrations
This helps solve the problem of migrating out of order or missed migration files. So when you migrate up, it will now run any migrations that have not been run, and when you migrate down, it will ignore migrations that have not been run. To help with this feature, the table that Migrations uses to keep track of the current version has been replaced with one that keeps a record of every migration that has been run.
Migrations love Arrays too
OK, so not everyone likes YAML, so I gave in. Migrations now supports native PHP arrays within your migration files. Something like this:
In fact, this now means you can use any old PHP code within your migrations. Opens up some nice possibilities.
New command: “migrate info”
A new command has been added that shows you the full list of migration files, along with some really useful info, such as what migrations have been run, and when.
Migrating Specific files
You can now also migrate a specific UP or DOWN section from any migration file. How specific is that?
Those are the changes so far, there may well be one or two more to come before the release candidate, but I am still looking into those and will be posting on them very soon. You can also expect to see some bug fixes by the time the release candidate arrives.
So please download and play to your hearts content. If you discover any bugs, or if you have any ideas for enhancements and want to see them included in this release, please create an issue. If you just want to leave a comment and talk to me about this, leave your comment below.
My name is Joel Moss, a web developer and all round nice guy, living in Manchester, England. I am currently working full time for ShermansTravel.com, but I fill whatever spare time I have with lots of good and wholesome "stuff"! Like developing my own ideas; such as Tooum, contributing to the excellent CakePHP framework, and doing more work for ShermansTravel.
So this is my blog - my soap box! Here I attempt to share my likes, my dislikes, and my opinions. As well as providing some occasional respite from the daily crap we all endure. Enjoy ;)
Hey, if you want to reach me, i'm available via email:joel[at]developwithstyle[dot]com, and AIM:joelkmoss.
Derick
May 21st, 2008 at 2:10 am
Neato! Erm, I went through the examples and I can’t find how to switch the table type to InnoDB. I guess it would be nice to have the list of actions (e.g. “add_fields”, “query”, etc.) and params explained in the http://code.google.com/p/cakephp-migrations/wiki/HowToUse. Although the examples do roughly explain certain things, I am sure there are “hidden” stuffs!
Joel
May 21st, 2008 at 8:25 am
@Derick Unfortunately, the only way to change a tables type is using a raw SQL query.
I do plan on writing up more on the commands supported.
Huey
June 20th, 2008 at 8:14 pm
Migrations were one of the few things I missed from RoR and this implementation is great! I found a bug and thought of a feature.
The Bug
The fields in the SQL generated are not wrapped in (`). This doesn’t normally cause an error but I was trying to create a table with an order field so I could store the order for the post and it errored on me. I checked out the SQL it was trying to run and it looked like it had order instead of `order` which was killing the query.
The Feature
I love the timestamp naming convention, but miss the ease of running “migrate up 1″ instead of “migrate up 123456435″. So I was thinking about it and thought that it would be cool if you implemented a shortcut number so when we run “migrate info” it will have the usual information but assign each migration a shortcut (e.g. #1 [1213585198] Create Users Table (migrated: Fri, 20 Jun 2008 11:13:15 -0400)) then we could run “migrate up #1″ to migrate the first one and since it’s not stored in the file system there would be no collisions.
Anyways, love the script! Keep up the good work!
Ziad
July 3rd, 2008 at 5:24 pm
Hi Joel,
Thanks for all your work on migrations. However, I am a little stuck with using migrations and a little confused about what is the best practice.
The problem that I am having is that I am using CakePHP 1.2 with a postgres 8.2 database. In my database.php I have set (correctly I believe) the driver to ‘postgres’ but when I run migrate from the console I get error message that the PEAR driver could not be found because its looking for MDB2/Driver/postgres.php but the file is actually called MDB2/Driver/pgsql.php. I can get around this by setting up another connection with the pgsql driver but I dont think this is a good solution.
The other problem I am having is making the decision between migrations and schema. Please see:
http://cakebaker.42dh.com/2008/04/13/migrations-the-cakephp-way/
Here there seems to be a difference of opinion as to which method is better (see comment by Nate). What are your thoughts on this?
Thanks
Ziad