Cake Schema Migrations

franzem edited this page Oct 28, 2011 · 3 revisions

If you would like to make sure that Capcake also makes the necessary database changes:

from your APP folder, run cake schema generate, choose [O]verwrite add/commit/push those changes to GITHub

add the following task to your config/deploy.rb file:

namespace(:customs) do
  task :schema, :roles => :app, :only => {:primary => true}  do
    run  run "TERM='dumb' && export TERM && /var/www/sites/cakephp/cake/console/cake -app #{deploy_to}/current schema update" do |ch, stream, out|
    ch.send_data "y"+"\n" if out =~ /Are you sure you want to alter the tables/
    print out

after "deploy:symlink", customs:schema"

the ch.send_data is required to answer the prompt 'y' and print out is required so you can see what the task has done

The " :only => {:primary => true} " is important if you are running multiple servers with MySQL replication. Without this the schema is updated twice, leading to conflicts in the slave DB's and throwing the replication out.