Good DB Migrations for CakePHP?
Asked Answered
S

5

18

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:

Succession answered 26/3, 2010 at 10:8 Comment(5)
By ignoring the documentation and reading the source I have discovered how to make the Schema Shell do pretty much all I need. I found out that -f does not "force 'generate' to create a new schema.". It is used "To force generation of all tables into the schema...". But not only that, and this is not in the docs: It can also be used to force update to ignore the Model classes in the same way as generate and therefore update a schema generated using the option.Succession
@Matin Westin -- why not contribute those insights to the documentation wiki?Poltroonery
If you are referring to book.cakephp.org the I did... as I always do.Succession
Could you write up your comment into a proper answer to your own question, so it can be accepted and voted up and such?Limekiln
I was about to when I discovered that for my usecase the Schema Shell does seem to have a fatal flaw, so I'm still looking and will try to find the time to check Juans migrations asap.Succession
S
4

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.

Succession answered 31/3, 2010 at 12:20 Comment(0)
A
3

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.

Avelinaaveline answered 9/5, 2012 at 16:59 Comment(1)
I'm a fan of Ruby. Now have to deal with PHP projects. I hope Rails Migrations will ease my job a bit :)Gordon
H
2

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...

Haler answered 26/3, 2010 at 13:16 Comment(0)
T
1

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.

Taenia answered 29/6, 2012 at 18:2 Comment(0)
E
0

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.

Entomophagous answered 6/10, 2016 at 20:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.