Doctrine 1
  1. Doctrine 1
  2. DC-931

Newly generated Migration Classes failing to load due to method used to determine class name

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.0-ALPHA1, 1.2.0-ALPHA2, 1.2.0-ALPHA3, 1.2.0-BETA1, 1.2.0-BETA2, 1.2.0-BETA3, 1.2.0-RC1, 1.2.0, 1.2.1, 1.2.2, 1.2.3
    • Fix Version/s: None
    • Component/s: Migrations
    • Labels:
      None
    • Environment:
      LAMP

      Description

      The loadMigrationClassesFromDirectory() method in Doctrine_Migration uses array_diff on get_declared_classes() between including each classes script.

      When a new migration class is generated by Doctrine_Core::generateMigrationsFromDiff it's class is loaded, which means loadMigrationClassesFromDirectory silently fails to load the newly generated migration on the same request. This means that scripts that first generate migrations and then apply them must be executed twice - first to generate then to apply.

      The following example code is used to check if the database has been modifed, generate migrations between the base version and the latest models, and then migrate the database if needed:

      automigrate.php
      Doctrine_Core::generateYamlFromModels(ROOT_PATH.'tmp/yaml/', ROOT_PATH.'models/');
      $result = Doctrine_Core::generateMigrationsFromDiff(ROOT_PATH.'tmp/migrations/', ROOT_PATH.'data/yaml/', ROOT_PATH.'tmp/yaml/');
      
      unlink(ROOT_PATH.'data/yaml/schema.yml');
      rename(ROOT_PATH.'tmp/yaml/schema.yml', ROOT_PATH.'data/yaml/schema.yml');
      
      $migration = new Doctrine_Migration(ROOT_PATH.'tmp/migrations');
      
      $currentVersion = $migration->getCurrentVersion();
      $latestVersion = $migration->getLatestVersion();
      if ($currentVersion < $latestVersion) {
      	$migration->migrate();
      	$this->app->addMessage("Database migration completed (from version $currentVersion to version $latestVersion)","success");
      } else {
      	$this->app->addMessage("Database is up to date and doesn't require migration (at version $currentVersion)","success");
      }
      
      

        Activity

        Adam Benson created issue -
        Guilherme Blanco made changes -
        Field Original Value New Value
        Affects Version/s 1.2.4 [ 10063 ]

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Adam Benson
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: