[DMIG-36] Iterating over versions is very slow Created: 05/Mar/13  Updated: 22/Dec/13

Status: Open
Project: Doctrine Migrations
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Eric Durand-Tremblay Assignee: Benjamin Eberlei
Resolution: Unresolved Votes: 1
Labels: None


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){


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

public function createMigrationTable()

        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);

            $this->migrationTableCreated = true;

            return true;
        return false;

Comment by Jeroen Thora [ 14/Jul/13 ]

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

Comment by Jeroen Thora [ 22/Dec/13 ]

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

Generated at Wed Nov 25 22:29:27 EST 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.