CakePHP 的良好数据库迁移?
我一直在尝试一些 CakePHP 的迁移脚本,但我遇到了各种形式的问题。
请向我提供有关您实际使用且知道有效的 Cake 迁移选项的建议。
我想要以下“功能”:
- 支持 CakePHP 1.2(例如,只有当 1.3 稳定并且我的应用程序迁移到新的代码库时,CakeDCs 迁移才是一个选项)
- 支持(或至少不会停止)具有不同数据库的模型配置。
- 支持 app/models 子文件夹中的模型
- 支持插件中的模型 支持
- 不符合 Cake 约定的表(我有一些没有单个主键字段的特殊表,需要保留它们)
- 与自动化部署配合良好通过 Capistrano 和 Git。
我不需要 Rails 风格的版本化文件,只需将 git 版本化架构文件与现有架构进行实时比较即可。也就是说:我喜欢 Cake 中的 SchemaShell,除了它与我上面的大多数要求不兼容。
我查看并测试了:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在快速尝试了 Juan 的插件和除 CakeDC 之外提到的所有其他插件后,我将尝试用我的发现更新这个“主题”...因为我没有为 CakePHP 1.3 更新相关应用程序,并且迁移插件需要 1.3
我必须注意,有关失败和不适合我的插件的评论应主要解读为“不适合我的需求”或“我在尝试它们时犯的错误”。在某种程度上,有些人可能会将此类评论视为对文档进行修订的请求。我并不是说所测试的插件本身就有缺陷、有问题或损坏。我确信它们都在正确的环境和正确的工作流程下工作。
CakePHP Schema Shell
有我喜欢的简单概念。架构链接到代码,SCM 用于管理其修订。
在某种程度上效果很好。这一点是:
似乎不适合自动化部署。即update命令只能修改表,不能处理新的或删除的表。这些由它们自己的 shell 命令处理,使得 Cap 式部署变得复杂。当脚本尝试“更改”不存在的表时,使用新表运行更新也会产生错误。我确定这是有意为之还是我遇到的问题。 (已在 Google 群组中询问,尚未回复)
CakeDC 迁移
YAML、joelmoss 和 juan 的迁移
这些都共享版本化文件以及它们之间的“upping”和“downing”的 Rails 概念。我不太喜欢这个,因为我看不到我的项目在更新或回滚模式迁移时不对源代码执行相同操作的情况。我也可以在没有迁移脚本中迁移现有数据的能力的情况下生活,因为我预见到这种情况对我来说非常罕见。
这些都期望我不通过迁移脚本以外的任何其他方式接触数据库。我无法打开我最喜欢的 MySql-GUI 并玩弄直到我满意为止,然后通过这些脚本生成“差异”。 (至少在我的简短测试中我还没有找到记录的方法。)我必须手动在 YAML 或 php 文件中编写更改。由于我开始处理一个包含大约 30 个表的现有项目,因此我不喜欢手动重写该架构的想法。但是其中一些插件没有为我的所有表创建一个良好的起点文件。这也可能是由于我的简短测试和/或无法找到此类功能的文档。我没有深入研究其中大部分的源代码。
我的下一步是将我的项目更新到 CakePHP 1.3 并尝试最后一个插件。但我不知道什么时候才能有时间。 (也就是说,没有人屏住呼吸)
如果您认为我误解了这些插件的工作原理,并且可以提供有关如何使它们为我工作的建议。我很乐意回复评论。
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
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.
如果您喜欢 Rails 迁移,请使用 Rails Migrations...看看这个 gem https://github.com /thuss/standalone-migrations 。我在日常工作中将这个 gem 与 cakephp 一起使用。
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.
我有一个可以升级到 CakePHP 1.2 的插件,你可以在 http://github.com/jrbasso/migrations 中看到
它使用蛋糕风格来制作所有东西。不使用yaml,使用对象来定义表。您可以毫无问题地从 Cake 导入模型...
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...
我在生产环境中使用了 1.3.x 和 2.x 的 CakeDC 迁移插件,并且很高兴。 1.3.x 版本中存在一些与创建迁移相关的错误,但它们很容易修复。
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.
此处使用 3.x Migrations 插件。
其他旧工具存在的所有问题均已通过设计解决。
它正在大力开发中,每周都会获得更多功能和修复。
您还可以轻松地将新工具用于现有的 1.x 和 2.x 应用程序。
我刚刚发布了一篇关于 如何在 2.x 应用程序中使用 3.x 迁移 顺便说一下。
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.