Skip to content

Commit fccdf7c

Browse files
committed
character and collation not needed for some columns on change
1 parent 0557622 commit fccdf7c

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

src/Illuminate/Database/Schema/Grammars/ChangeColumn.php

+25-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ protected static function getDoctrineColumnChangeOptions(Fluent $fluent)
121121
$options['length'] = static::calculateDoctrineTextLength($fluent['type']);
122122
}
123123

124-
if (in_array($fluent['type'], ['json', 'binary'])) {
124+
if (static::doesntNeedCharacterOptions($fluent['type'])) {
125125
$options['customSchemaOptions'] = [
126126
'collation' => '',
127127
'charset' => '',
@@ -178,6 +178,30 @@ protected static function calculateDoctrineTextLength($type)
178178
}
179179
}
180180

181+
/**
182+
* Determine if the given type does not need character / collation options.
183+
*
184+
* @param string $type
185+
* @return bool
186+
*/
187+
protected static function doesntNeedCharacterOptions($type)
188+
{
189+
return in_array($type, [
190+
'bigInteger',
191+
'binary',
192+
'date',
193+
'decimal',
194+
'double',
195+
'float',
196+
'integer',
197+
'json',
198+
'mediumInteger',
199+
'smallInteger',
200+
'time',
201+
'tinyInteger',
202+
]);
203+
}
204+
181205
/**
182206
* Get the matching Doctrine option for a given Fluent attribute name.
183207
*

tests/Database/DatabaseSchemaBlueprintIntegrationTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testRenamingAndChangingColumnsWork()
6060
$expected = [
6161
'CREATE TEMPORARY TABLE __temp__users AS SELECT name, age FROM users',
6262
'DROP TABLE users',
63-
'CREATE TABLE users (name VARCHAR(255) NOT NULL COLLATE BINARY, age INTEGER NOT NULL COLLATE BINARY)',
63+
'CREATE TABLE users (name VARCHAR(255) NOT NULL COLLATE BINARY, age INTEGER NOT NULL)',
6464
'INSERT INTO users (name, age) SELECT name, age FROM __temp__users',
6565
'DROP TABLE __temp__users',
6666
'CREATE TEMPORARY TABLE __temp__users AS SELECT name, age FROM users',
@@ -266,7 +266,7 @@ public function testAddUniqueIndexWithNameWorks()
266266
$expected = [
267267
'CREATE TEMPORARY TABLE __temp__users AS SELECT name FROM users',
268268
'DROP TABLE users',
269-
'CREATE TABLE users (name INTEGER UNSIGNED DEFAULT NULL COLLATE BINARY)',
269+
'CREATE TABLE users (name INTEGER UNSIGNED DEFAULT NULL)',
270270
'INSERT INTO users (name) SELECT name FROM __temp__users',
271271
'DROP TABLE __temp__users',
272272
'alter table "users" add constraint "index1" unique ("name")',
@@ -283,7 +283,7 @@ public function testAddUniqueIndexWithNameWorks()
283283
$expected = [
284284
'CREATE TEMPORARY TABLE __temp__users AS SELECT name FROM users',
285285
'DROP TABLE users',
286-
'CREATE TABLE users (name INTEGER UNSIGNED DEFAULT NULL COLLATE BINARY)',
286+
'CREATE TABLE users (name INTEGER UNSIGNED DEFAULT NULL)',
287287
'INSERT INTO users (name) SELECT name FROM __temp__users',
288288
'DROP TABLE __temp__users',
289289
'create unique index "index1" on "users" ("name")',
@@ -300,7 +300,7 @@ public function testAddUniqueIndexWithNameWorks()
300300
$expected = [
301301
'CREATE TEMPORARY TABLE __temp__users AS SELECT name FROM users',
302302
'DROP TABLE users',
303-
'CREATE TABLE users (name INTEGER UNSIGNED DEFAULT NULL COLLATE BINARY)',
303+
'CREATE TABLE users (name INTEGER UNSIGNED DEFAULT NULL)',
304304
'INSERT INTO users (name) SELECT name FROM __temp__users',
305305
'DROP TABLE __temp__users',
306306
'create unique index "index1" on "users" ("name")',

tests/Integration/Database/SchemaBuilderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function testRegisterCustomDoctrineType()
5656
$expected = [
5757
'CREATE TEMPORARY TABLE __temp__test AS SELECT test_column FROM test',
5858
'DROP TABLE test',
59-
'CREATE TABLE test (test_column TINYINT NOT NULL COLLATE BINARY)',
59+
'CREATE TABLE test (test_column TINYINT NOT NULL)',
6060
'INSERT INTO test (test_column) SELECT test_column FROM __temp__test',
6161
'DROP TABLE __temp__test',
6262
];

0 commit comments

Comments
 (0)