From 6edca814227ace004dbce0465e3f3bfe6387ab7e Mon Sep 17 00:00:00 2001 From: Amelia Ikeda Date: Mon, 17 Oct 2016 16:18:28 +0100 Subject: [PATCH 1/4] Fix migrate:rollback breaking due to a missing schema grammar (fixes #15892) --- .../Database/Migrations/Migrator.php | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Illuminate/Database/Migrations/Migrator.php b/src/Illuminate/Database/Migrations/Migrator.php index c11590a41bbb..6270955a8ddb 100755 --- a/src/Illuminate/Database/Migrations/Migrator.php +++ b/src/Illuminate/Database/Migrations/Migrator.php @@ -160,9 +160,7 @@ protected function runUp($file, $batch, $pretend) return $this->pretendToRun($migration, 'up'); } - $this->runMigration(function () use ($migration) { - $migration->up(); - }); + $this->migrate($migration, 'up'); // Once we have run a migrations class, we will log that it was run in this // repository so that we don't try to run it next time we do a migration @@ -282,9 +280,7 @@ protected function runDown($file, $migration, $pretend) return $this->pretendToRun($instance, 'down'); } - $this->runMigration(function () use ($instance) { - $instance->down(); - }); + $this->runMigration($instance, 'down'); // Once we have successfully run the migration "down" we will remove it from // the migration repository so it will be considered to have not been run @@ -364,12 +360,19 @@ protected function getQueries($migration, $method) /** * Run a migration inside a transaction if the database supports it. * - * @param \Closure $callback + * @param object $migration + * @param string $method * @return void */ - protected function runMigration(Closure $callback) + protected function runMigration($migration, $method) { - $connection = $this->resolveConnection($this->connection); + $name = $migration->getConnection(); + + $connection = $this->resolveConnection($name); + + $callback = function () use ($migration, $method) { + $migration->$method(); + }; $grammar = $connection->getSchemaGrammar(); From e018d91294e81028507e01bb6ac646ba91c23ca2 Mon Sep 17 00:00:00 2001 From: Amelia Ikeda Date: Mon, 17 Oct 2016 16:52:20 +0100 Subject: [PATCH 2/4] If the default schema grammar is not set, pull it out --- .../Database/Migrations/Migrator.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Migrations/Migrator.php b/src/Illuminate/Database/Migrations/Migrator.php index 6270955a8ddb..3220d9a0311f 100755 --- a/src/Illuminate/Database/Migrations/Migrator.php +++ b/src/Illuminate/Database/Migrations/Migrator.php @@ -374,13 +374,30 @@ protected function runMigration($migration, $method) $migration->$method(); }; - $grammar = $connection->getSchemaGrammar(); + $grammar = $this->getSchemaGrammar($connection); $grammar->supportsSchemaTransactions() ? $connection->transaction($callback) : $callback(); } + /** + * Get the schema grammar out of a migration connection. + * + * @param \Illuminate\Database\Connection $connection + * @return \Illuminate\Database\Schema\Grammars\Grammar + */ + protected function getSchemaGrammar($connection) + { + if (is_null($grammar = $connection->getSchemaGrammar())) { + $connection->useDefaultSchemaGrammar(); + + $grammar = $connection->getSchemaGrammar(); + } + + return $grammar; + } + /** * Resolve a migration instance from a file. * From 5aa9a6d5151ca983e3a2c6b638e46e240c14be1f Mon Sep 17 00:00:00 2001 From: Amelia Ikeda Date: Mon, 17 Oct 2016 16:58:23 +0100 Subject: [PATCH 3/4] Remove an unused import --- src/Illuminate/Database/Migrations/Migrator.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Illuminate/Database/Migrations/Migrator.php b/src/Illuminate/Database/Migrations/Migrator.php index 3220d9a0311f..b3f271f67858 100755 --- a/src/Illuminate/Database/Migrations/Migrator.php +++ b/src/Illuminate/Database/Migrations/Migrator.php @@ -2,7 +2,6 @@ namespace Illuminate\Database\Migrations; -use Closure; use Illuminate\Support\Arr; use Illuminate\Support\Str; use Illuminate\Support\Collection; From 778350e5d6a59c4670251ca6b6e0419f801368ba Mon Sep 17 00:00:00 2001 From: Amelia Ikeda Date: Mon, 17 Oct 2016 16:59:44 +0100 Subject: [PATCH 4/4] Fix a method naming error --- src/Illuminate/Database/Migrations/Migrator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Migrations/Migrator.php b/src/Illuminate/Database/Migrations/Migrator.php index b3f271f67858..49e7ac4dcb26 100755 --- a/src/Illuminate/Database/Migrations/Migrator.php +++ b/src/Illuminate/Database/Migrations/Migrator.php @@ -159,7 +159,7 @@ protected function runUp($file, $batch, $pretend) return $this->pretendToRun($migration, 'up'); } - $this->migrate($migration, 'up'); + $this->runMigration($migration, 'up'); // Once we have run a migrations class, we will log that it was run in this // repository so that we don't try to run it next time we do a migration