进行迁移差异的正确方法

发布于 2024-10-10 06:35:08 字数 1052 浏览 0 评论 0原文

我正在尝试使用以下代码在架构 yaml 文件和我的数据库之间执行迁移差异

    $migration = new Doctrine_Migration($migrationsPath);
    $diff = new Doctrine_Migration_Diff(null, $yamlSchemaPath, $migration);
    $changes = $diff->generateMigrationClasses();

    $numChanges = count($changes, true) - count($changes);

从我收集到的信息来看,这里的 $from = null 意味着比较中的 from 将从数据库中读取,但这并不意味着似乎是这样。

阅读此处我已执行以下步骤以确保基本的惯例并没有错。

  1. 将 yaml 文件
  2. generate-migrations-diff 更改为 diff 您当前(已更改)的 yaml 为 您的(未更改的)模型。这将 在您的中生成一个迁移文件 学说/迁移目录(或 无论migrations_path设置为什么 在你的学说配置中)。
  3. migrate 运行创建的迁移 在步骤 2 中修改数据库
  4. generate-models-yaml 以生成新的 基于您的 yaml 文件的类。 这些去你指定的地方 生成的模型进入(models_path in 你的学说配置)。
  5. generate-sql 生成 SQL 文件。 这将去往你的教义所在 sql_path 配置设置为。

当架构 yaml 文件未更改时,$numChanges 始终相同。它不会与同步且工作的当前数据库进行比较。

有人可以发现错误或者告诉我正确的方法吗?

I'm trying to perform a migrations diff between the schema yaml file and my database, using the following code

    $migration = new Doctrine_Migration($migrationsPath);
    $diff = new Doctrine_Migration_Diff(null, $yamlSchemaPath, $migration);
    $changes = $diff->generateMigrationClasses();

    $numChanges = count($changes, true) - count($changes);

From what I gather, $from = null here would imply that the from in comparison will be read from the database, but that does not seem to be the case.

Reading about it here i've performed the following steps to make sure the basic routine is not at fault.

  1. Change yaml file
  2. generate-migrations-diff to diff
    your current (changed) yaml with
    your (unchanged) models. This will
    generate a migrations file in your
    doctrine/migrations directory (or
    whatever migrations_path is set to
    in your doctrine config).
  3. migrate to run the migration created
    in step 2 and modify your database
  4. generate-models-yaml to generate new
    classes based on your yaml file.
    These go where you've specified your
    generated models go (models_path in
    your doctrine config).
  5. generate-sql to generate a SQL file.
    This will go where your doctrine
    sql_path config is set to.

The $numChanges is always the same when the schema yaml file isn't changed. It does not compare against the current database that is in sync and working.

Can someone spot an error or perhaps tell me the correct way of doing it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文