diff --git a/src/Phinx/Migration/Manager.php b/src/Phinx/Migration/Manager.php index 7edf09d67..d0d18a019 100644 --- a/src/Phinx/Migration/Manager.php +++ b/src/Phinx/Migration/Manager.php @@ -546,7 +546,7 @@ public function dumpSchema($environment, $outfile=false) $seeds = $config->getSeeds($adapter); $seed_table_names = array_map(function ($s) {return $s->getName();}, $seeds); - + $args = array_map(function ($list) { $c=count($list); $s=$c==1?'':'s'; return array($c, $s); }, array($tables, $seeds)); $output->writeln( sprintf("Schema dump includes %d table%s (%d seed table%s)", @@ -567,12 +567,12 @@ public function dumpSchema($environment, $outfile=false) $foreign_keys[] = $fk; if (preg_match('/REFERENCES [`"\']?(\w+)\b/i', $fk, $m)) { # this $table depends on the reference table to be inserted into first - # set the seed table dependency + # set the seed table dependency # # only do this if not a self-circular dependency if ($table->getName()!=$m[1]) { - // if both the table and the foreign key table are in the seed + // if both the table and the foreign key table are in the seed // list, set the dependency, otherwise we're wasting time if (static::listContainsAll($seed_table_names, $table->getName(), $m[1])) { $ret = static::getSeed($table->getName(), $seeds) @@ -592,11 +592,13 @@ public function dumpSchema($environment, $outfile=false) fwrite($f, "\n"); } + // start a new transaction to speed up inserts + fwrite($f, "START TRANSACTION;\n"); $processed = array(); // this will have an infinite loop if we have circular dependency. - // A -> B -> C -> A, or A->A. These are explicitly detected before hand and + // A -> B -> C -> A, or A->A. These are explicitly detected before hand and // removed. so we *shouldn't* loop forever. just in case, we'll count $n = 0; while (count($processed) != count($seeds)) { @@ -631,6 +633,8 @@ public function dumpSchema($environment, $outfile=false) } } } + // commit all the inserts in the end + fwrite($f, "COMMIT;\n"); } private static function getSeed($name, &$seeds)