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
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.
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.
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...
I've used the CakeDC migrations plugin for 1.3.x and 2.x in production environments and have been pleased. There are some bugs related to creating migrations in the 1.3.x version, but they're easy to fix.
Use the 3.x Migrations plugin here.
All the issues the other older tools have are fixed by design. And it is under heavy development and gets more features and fixes every week.
You can also easily use the new tool for existing 1.x and 2.x apps. I just released a post on how to use 3.x Migrations in 2.x apps by the way.
来源:https://stackoverflow.com/questions/2522372/good-db-migrations-for-cakephp