Correct way to do a migrations diff

2019-08-10 12:42发布

问题:

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?