Today we will talk about migrations, yaml files and CakePHP and in particular I’ll introduce you to the latest shell I’ve written for CakePHP: “*_YAMMY!_*”:http://www.4webby.com/blog/posts/view/3/yammy_db_to_yaml_shell_migrations_made_easy_in_cakephp
I’ve written YAMMY! a couple of weeks ago, but I just found the time to release it today. Anyway lets get into more details!
h2. WHAT ARE MIGRATIONS?
Well migrations are what “revision control systems”:http://en.wikipedia.org/wiki/Version_control (“SVN”:http://subversion.tigris.org/ or “CVS”:http://www.nongnu.org/cvs/) is for files but applied to database tables.
Migrations allow you to define changes to your database schema, making it possible to use a version control system to keep things synchronized with the actual code.
This has many uses, including:
# Teams of developers: if one person makes a schema change, the other developers just need to update, and they can simply run a migration.
# Production servers: use migrations when you roll out a new release to bring the database up to date as well.
# Multiple machines: if you develop on both a desktop and a laptop, or in more than one location, migrations can help you keep them all synchronised.
h2. MIGRATIONS IN CAKEPHP
“Joel Moss”:http://joelmoss.info/ brought migrations to CakePHP in 2006, with his excellent migration shell, that has now reached “version 3.3″:http://joelmoss.info/switchboard/blog/2583:Migrations_v33.
Now you are nearly ready to go with YAMMY! and to speed up your application development and project management.
h2. YAMMY!: feed your migrations faster
The “CakePHP”:http://www.cakephp.org migration infrastructure described above needs the “right food” in order to work properly.
To use migrations you need to provide some files in “YAML format”:http://www.yaml.org/ telling the migration shell what to do. Writing a DB table structure in a yaml format is pretty boring and time consuming: YAMMY! enters into the game here.
*YAMMY! provides a convenient and super fast way to feed your migrations converting your DB tables schema into a YAML format in few seconds.*
h2. YAMMY! requirements
Before I’ll go into further details let’s see what you need to use YAMMY!
You then need to configure your PATH environment variable in order to tell your server where the hell cake is located. These two screencats will help you sorting these out:
# “Setting Up the CakePHP Console on *nix”:http://cakephp.org/screencasts/view/7
# “Setting Up the CakePHP Console on Windows”:http://cakephp.org/screencasts/view/6
You are now ready to go on!
# download the “Spyc class”:http://spyc.sourceforge.net/ and put it in your *app/vendors* directory
# “download YAMMY! 1.0″:http://www.4webby.com/blog/posts/view/3/downloads and put it in your *app/vendors/shells* directory
h2. YAMMY! in action
Now if you set the CakePHP console properly as described in the two screencasts above, you are ready to go!
Open your Shell/Console and move (cd ..) to your app directory (on my development machine I have all my projects in _C:\www_ for example, lets say I’m working on a project called test, I’ll them move to _C:\www\test\app_).
Once your Shell/Console points to your app directory type: @cake yammy@
Great you entered YAMMY! in interactive mode and YAMMY! will ask you which tables you want to convert.
After answering a few questions (the DB connection you wanna use and which tables you want to convert to yaml files) YAMMY! will write a file in *app/config/migrations* with your DB schema converted to a YAML format, and you are ready to start your migrations wih the migration shell!
For a complete overview of all YAMMY! functionality type in your console: @cake yammy help@
Don’t worry, your DB tables will stay untouched, what YAMMY! does is simply to write their structure in a YAML format into a file in app/migrations.
h2. YAMMY! benefits
What the benefits of using migrations and YAMMY! for your development cycle?!?
Well they help you to keep your development tidy and to speed up the all process.
If you then use a tool like “Capistrano”:http://www.capify.org/ (“read this post by Chris Hartjes”:http://www.littlehart.net/atthekeyboard/2007/09/21/deploying-cakephp-applications-using-capistrano/) you can not only deploy your application faster but even run migrations remotely.
I hope that you will find YAMMY! usefull and that you will have more time to sunbath on the beach using it along with migrations!
h2. YAMMY! downloads, resources & userguide
You can find a more detailed descriptioin of YAMMY! and download it on the “4webby Blog”:http://www.4webby.com/blog/posts/view/3/yammy_db_to_yaml_shell_migrations_made_easy_in_cakephp.
You will also find screenshots of the YAMMY! shell.