教义迁移在生产应用中是否可用? [英] Are Doctrine migrations usable in production applications?

查看:137
本文介绍了教义迁移在生产应用中是否可用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于以前讨论过的,我们正在开发PHP Zend Framework的应用程序需要在数据库升级过程中非常频繁地以跨数据库的方式进行开发。

As previously discussed, we are developing a PHP application around Zend Framework that needs to have it's database upgraded quite frequently and in a cross-database way as we move through development stages.

我们正在使用Rails迁移虽然他们是在Ruby中(而在Windows上的Ruby是它的混乱),但我们很难将迁移分发给具有基于Windows的安装的客户。即使在Linux上,使用Ruby也可以访问MS SQL和Oracle数据库。

We are currently using Rails Migrations for this, although with them being in Ruby (and Ruby on Windows being the mess that it is), we are having a hard time distributing migrations to customers that have Windows-based installs. Even on Linux, access to MS SQL and Oracle databases with Ruby is a pain.

我们要用Doctrine替代Rails Migrations,但是他们觉得很不成熟。没有太多的文档,跟踪器中有一些bug会引起项目状态的红旗,例如:

We want to replace Rails Migrations with Doctrine's, but they feel very immature. There isn't much documentation and there are some bugs in the tracker that raise red flags about the status of the project, such as:


  • renameColumn()删除列

  • < a href =https://github.com/doctrine/migrations/issues/17 =nofollow noreferrer>表重命名时的数据丢失

  • renameColumn() drops the column
  • Data loss on table renaming

查看代码,这两个实际上放弃原始表或列,并重新创建它,而不保留数据。这是一个完整的破产者,让我认为没有人真正使用Doctrine Migrations。

Looking at the code, those two actually drop the original table or column and recreate it without keeping the data. This is a total deal breaker that makes me think no one really uses Doctrine Migrations.

此外,我阅读了文档中的迁移使用顺序编号(版本1,版本2等),使其完全不适合分支开发,然后 DoctrineMigrationsBundle Symfony documentation 使用基于日期的版本有意义。

Additionally, I read in the documentation that migrations use sequential numbering (version 1, version 2, etc) making them completely unsuitable for branchy development, but then the DoctrineMigrationsBundle Symfony documentation uses date-based versions that do make sense.

有没有人有这个工具的真实世界的经验,或者知道开发状态

Does anyone have real world experience with the tool, or know the development status of it?

推荐答案

我们已经看到了更多的Doctrine Migrations,并获得了对其内部运作的一些洞察(并更新了与OP也是这样)。

We have looked more into Doctrine Migrations and gained some insight on its inner workings (and updated the bugs linked in the OP as well).

主要的问题是,教义与迁移的方法截然不同。它从您的数据库模式构建一个抽象模型,然后允许您修改该模型。这些修改对基础数据库没有影响,但是Doctrine使用它们来推断在DB上必须进行的实际更改。

The main issue is that Doctrine has a fundamentally different approach to migrations. It constructs an abstract model out of your DB schema and then allows you to modify that model. These modifications have no impact on the underlying DB, but Doctrine uses them to infer the actual changes that have to be made on the DB.

这就像数据库的差异。这有一些非常讨厌的后果。例如,如果您重命名DB上的列,则该模型上的操作如下所示:

It's like diff for databases. This has some very nasty consequences. For example, if you rename a column on the DB the operation on the model looks like:

public function renameColumn($oldColumnName, $newColumnName)
{
    $column = $this->getColumn($oldColumnName);
    $this->dropColumn($oldColumnName);

    $column->_setName($newColumnName);
    return $this;
}

如果您使用此功能,然后使用Doctrine应用迁移,则会查看旧模式和新模式之间的差异(缺少列,添加的列及其类型),并推断是否需要重命名现有列或删除旧列,并创建新列。这意味着Doctrine认为重命名列与删除它并重新创建一样,实际上是一样的,因此非常愚蠢。

If you use this function and then have Doctrine apply the migration, it will then look at the differences between the old and the new schema (missing columns, added columns, and the types of those) and infer whether it needs to rename an existing column or drop the old one and create a new one. This means Doctrine thinks renaming a column is effectively the same as dropping it and creating it again, and therefore is very dumb about it.


  • 如果您重命名单个列,不要更改任何内容,它将在DBMS上发出重命名命令。

  • 如果重命名列并更改其类型(例如,varchar 80)到varchar(100),它将丢弃它并再次创建。

  • 如果您重命名2列,不要更改任何内容,它将会惊慌并将它们放在一起并重新创建它们(差分算法是那个初步的)

我认为这是DB迁移的一个坏方法,因为它不能可靠地工作这样一个工具的意义在于保持跨迁移的数据,这不符合基本要求。

I think it's a bad approach to DB migrations because it doesn't work reliably. The whole point of such a tool is keeping data across migrations and this fails that basic requirement.

这就是说,我们正在使用它,因为没有什么更好的在不可靠的操作中添加了故意的失败消息,以避免开发人员陷入许多pi垮台。

This said, we are using it anyway because there just isn't anything better. We added deliberate failure messages in the unreliable operations to avoid getting developers caught in the many pitfalls.

这篇关于教义迁移在生产应用中是否可用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆