Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good DB Migrations for CakePHP?

I have been trying a few migration scripts for CakePHP but I ran into problems with all of the in some form or another.

Please advice me on a migration option for Cake that you use live and know works.

I'd like the following "features":

  • Support CakePHP 1.2 (e.g. CakeDCs migrations will only be an option when 1.3 is stable and my app migrated to the new codebase)
  • Support for (or at least not halt on) Models with a different database config.
  • Support Models in sub-folders of app/models
  • Support Models in plugins
  • Support tables that do not conform to Cake conventions (I have a few special tables that do not have a single primary key field and need to keep them)
  • Plays well with automated deployment via Capistrano and Git.

I do not need rails-style versioned files a git versioned schema file that is compared live to the existing schema will do. That is: I like the SchemaShell in Cake apart from it not being compatible with most of my requirements above.

I have looked at and tested:

  • CakePHP Schema Shell http://book.cakephp.org/view/734/Schema-management-and-migrations
  • CakeDC migrations http://cakedc.com/downloads/view/cakephp_migrations_plugin
  • YAML migrations http://github.com/georgious/cakephp-yaml-migrations-and-fixtures
  • joelmoss migrations http://code.google.com/p/cakephp-migrations
like image 310
Martin Westin Avatar asked Mar 26 '10 10:03

Martin Westin


3 Answers

I'll try to update this "topic" with my findings after quickly trying Juan's plugin and all the others mentioned except the one from CakeDC... since I don't have the relevant app updated for CakePHP 1.3 and that migration plugin requires 1.3

I must note that comments about failures and plugins not working for me should be read primarily as "not suitable for MY needs" or "mistakes I have made while trying them". To some extent some might read such comments as a plea for a revision in documentation. I do not imply that the plugins tested are inherently flawed, buggy or broken. I am sure that all of them work under the right circumstances and for the right workflows.

CakePHP Schema Shell

  • Has the simple concept I like. The Schema is linked to the code and the SCM used to manage its revisions.

  • Works great to a point. That point being:

  • Does not appear suitable to automated deployment. I.e. The update command can only modify tables, not handle new or removed tables. Those are handled by their own shell commands making Cap-style deployment complicated. Also running updates with a new table will produce errors when the script tries to "Alter" the non-existing table. I am note sure if this is intended or a problem I am having. (Have asked on the google group with no reply yet)

CakeDC migrations

  • Sound like they took the Schema Shell and "fixed" it. The docs explain a procedure slightly more complicated (to explain at least) but it might work as I want it to.

YAML, joelmoss and juan's migrations

  • These all share the rails concept of versioned files and "upping" and "downing" between them. I like this less since I can not see a situation for my projects when the a schema migration would be updated or rolled back without doing the same to the source code. I can also live without the ability to migrate existing data in a migration script since I foresee that as a very rare occurrence for me.

  • These all expect me to not touch the database via any other means than migration scripts. I can not open my favorite MySql-GUI and play around until I am happy and then generate a "diff" via these scripts. (At least I have not found documented ways of doing it during my brief tests.) I have to manually write the changes in YAML or php files. Since I am starting out on an existing project with around 30 tables I do not relish the idea of re-writing that schema manually. But a few of these plugins did not create a good starting point-file with all my tables. This was also probably due to my brief testing and/or inability to find documentation for such a feature. I did not dive into the source code for most of these.

My next step looks to be updating my project to CakePHP 1.3 and give the last plugin a try. But I do not know when I will have time for it. (i.e. don't anyone hold their breath)

If you think I have misunderstood how any of these plugins work and can offer hits as to how to make them work for me. I'd be happy for a reply of a comment.

like image 130
Martin Westin Avatar answered Oct 12 '22 00:10

Martin Westin


If you like Rails migrations, use Rails Migrations... take a look at this gem https://github.com/thuss/standalone-migrations . I use this gem with cakephp in my daily work.

like image 24
rizidoro Avatar answered Oct 11 '22 22:10

rizidoro


I have a plugin that make it to CakePHP 1.2, you can see in http://github.com/jrbasso/migrations

It use cake style to make all things. Not uses yaml, uses objects to define tables. You can import models from Cake without problems...

like image 2
Juan Basso Avatar answered Oct 11 '22 23:10

Juan Basso