Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Fix #15892 by using the default schema grammar if not set. #15962

Merged
merged 4 commits into from
Oct 17, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions src/Illuminate/Database/Migrations/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Illuminate\Database\Migrations;

use Closure;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Support\Collection;
Expand Down Expand Up @@ -160,9 +159,7 @@ protected function runUp($file, $batch, $pretend)
return $this->pretendToRun($migration, 'up');
}

$this->runMigration(function () use ($migration) {
$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
Expand Down Expand Up @@ -282,9 +279,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
Expand Down Expand Up @@ -364,20 +359,44 @@ 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();

$grammar = $connection->getSchemaGrammar();
$connection = $this->resolveConnection($name);

$callback = function () use ($migration, $method) {
$migration->$method();
};

$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.
*
Expand Down