Skip to content

Commit 5dfafe4

Browse files
support modifying a char column type (#41320)
1 parent 03b673d commit 5dfafe4

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ protected static function getDoctrineColumnChangeOptions(Fluent $fluent)
125125
$options['length'] = static::calculateDoctrineTextLength($fluent['type']);
126126
}
127127

128+
if ($fluent['type'] === 'char') {
129+
$options['fixed'] = true;
130+
}
131+
128132
if (static::doesntNeedCharacterOptions($fluent['type'])) {
129133
$options['customSchemaOptions'] = [
130134
'collation' => '',
@@ -151,6 +155,7 @@ protected static function getDoctrineColumnType($type)
151155
'mediumtext', 'longtext' => 'text',
152156
'binary' => 'blob',
153157
'uuid' => 'guid',
158+
'char' => 'string',
154159
default => $type,
155160
});
156161
}

tests/Database/DatabaseSchemaBlueprintIntegrationTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,29 @@ public function testChangingColumnWithCollationWorks()
126126
$this->assertEquals($expected2, $queries2);
127127
}
128128

129+
public function testChangingCharColumnsWork()
130+
{
131+
$this->db->connection()->getSchemaBuilder()->create('users', function ($table) {
132+
$table->string('name');
133+
});
134+
135+
$blueprint = new Blueprint('users', function ($table) {
136+
$table->char('name', 50)->change();
137+
});
138+
139+
$queries = $blueprint->toSql($this->db->connection(), new SQLiteGrammar);
140+
141+
$expected = [
142+
'CREATE TEMPORARY TABLE __temp__users AS SELECT name FROM users',
143+
'DROP TABLE users',
144+
'CREATE TABLE users (name CHAR(50) NOT NULL COLLATE BINARY)',
145+
'INSERT INTO users (name) SELECT name FROM __temp__users',
146+
'DROP TABLE __temp__users',
147+
];
148+
149+
$this->assertEquals($expected, $queries);
150+
}
151+
129152
public function testRenameIndexWorks()
130153
{
131154
$this->db->connection()->getSchemaBuilder()->create('users', function ($table) {

0 commit comments

Comments
 (0)