Skip to content

Commit

Permalink
Merge pull request #28514 from JacksonIV/5.8
Browse files Browse the repository at this point in the history
[5.8] Fix the collation bug when changing columns in a migration.
  • Loading branch information
taylorotwell authored May 14, 2019
2 parents fab75c7 + 12e82c5 commit e459f37
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/ChangeColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ protected static function getTableWithColumnChanges(Blueprint $blueprint, Table
if (! is_null($option = static::mapFluentOptionToDoctrine($key))) {
if (method_exists($column, $method = 'set'.ucfirst($option))) {
$column->{$method}(static::mapFluentValueToDoctrine($option, $value));
continue;
}

$column->setCustomSchemaOption($option, static::mapFluentValueToDoctrine($option, $value));
}
}
}
Expand Down
37 changes: 37 additions & 0 deletions tests/Database/DatabaseSchemaBlueprintIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,43 @@ public function testRenamingAndChangingColumnsWork()
$this->assertEquals($expected, $queries);
}

public function testChangingColumnWithCollationWorks()
{
$this->db->connection()->getSchemaBuilder()->create('users', function ($table) {
$table->string('age');
});

$blueprint = new Blueprint('users', function ($table) {
$table->integer('age')->collation('RTRIM')->change();
});

$blueprint2 = new Blueprint('users', function ($table) {
$table->integer('age')->collation('NOCASE')->change();
});

$queries = $blueprint->toSql($this->db->connection(), new SQLiteGrammar);
$queries2 = $blueprint2->toSql($this->db->connection(), new SQLiteGrammar);

$expected = [
'CREATE TEMPORARY TABLE __temp__users AS SELECT age FROM users',
'DROP TABLE users',
'CREATE TABLE users (age INTEGER NOT NULL COLLATE RTRIM)',
'INSERT INTO users (age) SELECT age FROM __temp__users',
'DROP TABLE __temp__users',
];

$expected2 = [
'CREATE TEMPORARY TABLE __temp__users AS SELECT age FROM users',
'DROP TABLE users',
'CREATE TABLE users (age INTEGER NOT NULL COLLATE NOCASE)',
'INSERT INTO users (age) SELECT age FROM __temp__users',
'DROP TABLE __temp__users',
];

$this->assertEquals($expected, $queries);
$this->assertEquals($expected2, $queries2);
}

public function testRenameIndexWorks()
{
$this->db->connection()->getSchemaBuilder()->create('users', function ($table) {
Expand Down

0 comments on commit e459f37

Please sign in to comment.