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.8] Fix the collation bug when changing columns in a migration. #28514

Merged
merged 3 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
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
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