Skip to content

Commit

Permalink
character and collation not needed for some columns on change
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 30, 2020
1 parent 0557622 commit fccdf7c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
26 changes: 25 additions & 1 deletion src/Illuminate/Database/Schema/Grammars/ChangeColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ protected static function getDoctrineColumnChangeOptions(Fluent $fluent)
$options['length'] = static::calculateDoctrineTextLength($fluent['type']);
}

if (in_array($fluent['type'], ['json', 'binary'])) {
if (static::doesntNeedCharacterOptions($fluent['type'])) {
$options['customSchemaOptions'] = [
'collation' => '',
'charset' => '',
Expand Down Expand Up @@ -178,6 +178,30 @@ protected static function calculateDoctrineTextLength($type)
}
}

/**
* Determine if the given type does not need character / collation options.
*
* @param string $type
* @return bool
*/
protected static function doesntNeedCharacterOptions($type)
{
return in_array($type, [
'bigInteger',
'binary',
'date',
'decimal',
'double',
'float',
'integer',
'json',
'mediumInteger',
'smallInteger',
'time',
'tinyInteger',
]);
}

/**
* Get the matching Doctrine option for a given Fluent attribute name.
*
Expand Down
8 changes: 4 additions & 4 deletions tests/Database/DatabaseSchemaBlueprintIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testRenamingAndChangingColumnsWork()
$expected = [
'CREATE TEMPORARY TABLE __temp__users AS SELECT name, age FROM users',
'DROP TABLE users',
'CREATE TABLE users (name VARCHAR(255) NOT NULL COLLATE BINARY, age INTEGER NOT NULL COLLATE BINARY)',
'CREATE TABLE users (name VARCHAR(255) NOT NULL COLLATE BINARY, age INTEGER NOT NULL)',
'INSERT INTO users (name, age) SELECT name, age FROM __temp__users',
'DROP TABLE __temp__users',
'CREATE TEMPORARY TABLE __temp__users AS SELECT name, age FROM users',
Expand Down Expand Up @@ -266,7 +266,7 @@ public function testAddUniqueIndexWithNameWorks()
$expected = [
'CREATE TEMPORARY TABLE __temp__users AS SELECT name FROM users',
'DROP TABLE users',
'CREATE TABLE users (name INTEGER UNSIGNED DEFAULT NULL COLLATE BINARY)',
'CREATE TABLE users (name INTEGER UNSIGNED DEFAULT NULL)',
'INSERT INTO users (name) SELECT name FROM __temp__users',
'DROP TABLE __temp__users',
'alter table "users" add constraint "index1" unique ("name")',
Expand All @@ -283,7 +283,7 @@ public function testAddUniqueIndexWithNameWorks()
$expected = [
'CREATE TEMPORARY TABLE __temp__users AS SELECT name FROM users',
'DROP TABLE users',
'CREATE TABLE users (name INTEGER UNSIGNED DEFAULT NULL COLLATE BINARY)',
'CREATE TABLE users (name INTEGER UNSIGNED DEFAULT NULL)',
'INSERT INTO users (name) SELECT name FROM __temp__users',
'DROP TABLE __temp__users',
'create unique index "index1" on "users" ("name")',
Expand All @@ -300,7 +300,7 @@ public function testAddUniqueIndexWithNameWorks()
$expected = [
'CREATE TEMPORARY TABLE __temp__users AS SELECT name FROM users',
'DROP TABLE users',
'CREATE TABLE users (name INTEGER UNSIGNED DEFAULT NULL COLLATE BINARY)',
'CREATE TABLE users (name INTEGER UNSIGNED DEFAULT NULL)',
'INSERT INTO users (name) SELECT name FROM __temp__users',
'DROP TABLE __temp__users',
'create unique index "index1" on "users" ("name")',
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/Database/SchemaBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testRegisterCustomDoctrineType()
$expected = [
'CREATE TEMPORARY TABLE __temp__test AS SELECT test_column FROM test',
'DROP TABLE test',
'CREATE TABLE test (test_column TINYINT NOT NULL COLLATE BINARY)',
'CREATE TABLE test (test_column TINYINT NOT NULL)',
'INSERT INTO test (test_column) SELECT test_column FROM __temp__test',
'DROP TABLE __temp__test',
];
Expand Down

0 comments on commit fccdf7c

Please sign in to comment.