进行迁移差异的正确方法
我正在尝试使用以下代码在架构 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 将从数据库中读取,但这并不意味着似乎是这样。
阅读此处我已执行以下步骤以确保基本的惯例并没有错。
- 将 yaml 文件
- generate-migrations-diff 更改为 diff 您当前(已更改)的 yaml 为 您的(未更改的)模型。这将 在您的中生成一个迁移文件 学说/迁移目录(或 无论migrations_path设置为什么 在你的学说配置中)。
- migrate 运行创建的迁移 在步骤 2 中修改数据库
- generate-models-yaml 以生成新的 基于您的 yaml 文件的类。 这些去你指定的地方 生成的模型进入(models_path in 你的学说配置)。
- 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.
- Change yaml file
- 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). - migrate to run the migration created
in step 2 and modify your database - 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). - 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论