Skip to content

Commit

Permalink
[5.6] Quote collation name in MySQL migrations (#23989)
Browse files Browse the repository at this point in the history
* Quote collation name in MySQL migrations

* add brackets
  • Loading branch information
staudenmeir authored and taylorotwell committed Apr 25, 2018
1 parent 0c6f474 commit 6bf8c8a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ protected function compileCreateEncoding($sql, Connection $connection, Blueprint
// added to either this create table blueprint or the configuration for this
// connection that the query is targeting. We'll add it to this SQL query.
if (isset($blueprint->collation)) {
$sql .= ' collate '.$blueprint->collation;
$sql .= " collate '{$blueprint->collation}'";
} elseif (! is_null($collation = $connection->getConfig('collation'))) {
$sql .= ' collate '.$collation;
$sql .= " collate '{$collation}'";
}

return $sql;
Expand Down Expand Up @@ -862,7 +862,7 @@ protected function modifyCharset(Blueprint $blueprint, Fluent $column)
protected function modifyCollate(Blueprint $blueprint, Fluent $column)
{
if (! is_null($column->collation)) {
return ' collate '.$column->collation;
return " collate '{$column->collation}'";
}
}

Expand Down
10 changes: 5 additions & 5 deletions tests/Database/DatabaseMySqlSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testBasicCreateTable()
$statements = $blueprint->toSql($conn, $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertEquals('create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) not null) default character set utf8 collate utf8_unicode_ci', $statements[0]);
$this->assertEquals("create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) not null) default character set utf8 collate 'utf8_unicode_ci'", $statements[0]);

$blueprint = new Blueprint('users');
$blueprint->increments('id');
Expand Down Expand Up @@ -58,7 +58,7 @@ public function testEngineCreateTable()
$statements = $blueprint->toSql($conn, $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertEquals('create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) not null) default character set utf8 collate utf8_unicode_ci engine = InnoDB', $statements[0]);
$this->assertEquals("create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) not null) default character set utf8 collate 'utf8_unicode_ci' engine = InnoDB", $statements[0]);

$blueprint = new Blueprint('users');
$blueprint->create();
Expand All @@ -73,7 +73,7 @@ public function testEngineCreateTable()
$statements = $blueprint->toSql($conn, $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertEquals('create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) not null) default character set utf8 collate utf8_unicode_ci engine = InnoDB', $statements[0]);
$this->assertEquals("create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) not null) default character set utf8 collate 'utf8_unicode_ci' engine = InnoDB", $statements[0]);
}

public function testCharsetCollationCreateTable()
Expand All @@ -91,7 +91,7 @@ public function testCharsetCollationCreateTable()
$statements = $blueprint->toSql($conn, $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertEquals('create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) not null) default character set utf8mb4 collate utf8mb4_unicode_ci', $statements[0]);
$this->assertEquals("create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci'", $statements[0]);

$blueprint = new Blueprint('users');
$blueprint->create();
Expand All @@ -106,7 +106,7 @@ public function testCharsetCollationCreateTable()
$statements = $blueprint->toSql($conn, $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertEquals('create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) character set utf8mb4 collate utf8mb4_unicode_ci not null) default character set utf8 collate utf8_unicode_ci', $statements[0]);
$this->assertEquals("create table `users` (`id` int unsigned not null auto_increment primary key, `email` varchar(255) character set utf8mb4 collate 'utf8mb4_unicode_ci' not null) default character set utf8 collate 'utf8_unicode_ci'", $statements[0]);
}

public function testBasicCreateTableWithPrefix()
Expand Down

0 comments on commit 6bf8c8a

Please sign in to comment.