Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Labels:
      None

      Description

      When iterating migration versions, a call to SchemaManager::createSchema() is done for every versions. Four our schema, this call take about 1 second to execute. With already 30 migrations, this begin to be a problem.

      $versions = $configuration->registerMigrationsFromDirectory($this->_migration_folder);
      foreach($versions as $version){
          if(!$version->isMigrated()){
              $version->markMigrated();
          }
      
      }
      

      The problem is in Migrations\Configuration\Configuration::createMigrationTable() which does not set the migrationTableCreated flag when the table already exists.

      public function createMigrationTable()
      {
              $this->validate();
      
              if ($this->migrationTableCreated) {
                  return false;
              }
      
              $schema = $this->connection->getSchemaManager()->createSchema();
              if ( ! $schema->hasTable($this->migrationsTableName)) {
                  $columns = array(
                      'version' => new Column('version', Type::getType('string'), array('length' => 14)),
                  );
                  $table = new Table($this->migrationsTableName, $columns);
                  $table->setPrimaryKey(array('version'));
                  $this->connection->getSchemaManager()->createTable($table);
      
                  $this->migrationTableCreated = true;
      
                  return true;
              }
              return false;
      }
      

        Activity

        Hide
        Jeroen Thora added a comment - - edited

        We are experiencing the same problem, especialy when running migrations (plain sql queries) against a remote server. We have currently 4 migrations scripts, the first and second script contains the creation of around 10 tables (incl indexes, fk's, pk's, etc) this goes relativly fast (goes bit slower than running on a local server but that would be an amount of latancy) but when executing the third script (which only include a drop and create of an index) takes more than 60 seconds to execute. All these migration scripts are auto-generated by the diff tool

        After a bit of debugging it looks like the createSchema() function is called every migration but each migration script the database gets more tables and so it will take each migration more time to finish the createSchema() function

        The function is called here: https://github.com/doctrine/migrations/blob/master/lib/Doctrine/DBAL/Migrations/Version.php#L243

        First of all why is the create schema function needed to be executed and why every migration, because if you use plain sql migrations (auto-generated from mapping/entities) the migrations should just be executed, they don't need to know anything about the current state of the database except of the current migration version. So wouldn't it be a solution to check if the script containts plain sql or the migrations function and if it's just sql execute the migrations without checking the database

        Show
        Jeroen Thora added a comment - - edited We are experiencing the same problem, especialy when running migrations (plain sql queries) against a remote server. We have currently 4 migrations scripts, the first and second script contains the creation of around 10 tables (incl indexes, fk's, pk's, etc) this goes relativly fast (goes bit slower than running on a local server but that would be an amount of latancy) but when executing the third script (which only include a drop and create of an index) takes more than 60 seconds to execute. All these migration scripts are auto-generated by the diff tool After a bit of debugging it looks like the createSchema() function is called every migration but each migration script the database gets more tables and so it will take each migration more time to finish the createSchema() function The function is called here: https://github.com/doctrine/migrations/blob/master/lib/Doctrine/DBAL/Migrations/Version.php#L243 First of all why is the create schema function needed to be executed and why every migration, because if you use plain sql migrations (auto-generated from mapping/entities) the migrations should just be executed, they don't need to know anything about the current state of the database except of the current migration version. So wouldn't it be a solution to check if the script containts plain sql or the migrations function and if it's just sql execute the migrations without checking the database
        Hide
        Jeroen Thora added a comment - - edited

        Benjamin Eberlei & Marco Pivetta any idea's/update on this issue?

        Show
        Jeroen Thora added a comment - - edited Benjamin Eberlei & Marco Pivetta any idea's/update on this issue?

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Eric Durand-Tremblay
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: