Skip to content

Commit

Permalink
support modifying a char column type (#41320)
Browse files Browse the repository at this point in the history
  • Loading branch information
hafezdivandari authored Mar 3, 2022
1 parent 03b673d commit 5dfafe4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/ChangeColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ protected static function getDoctrineColumnChangeOptions(Fluent $fluent)
$options['length'] = static::calculateDoctrineTextLength($fluent['type']);
}

if ($fluent['type'] === 'char') {
$options['fixed'] = true;
}

if (static::doesntNeedCharacterOptions($fluent['type'])) {
$options['customSchemaOptions'] = [
'collation' => '',
Expand All @@ -151,6 +155,7 @@ protected static function getDoctrineColumnType($type)
'mediumtext', 'longtext' => 'text',
'binary' => 'blob',
'uuid' => 'guid',
'char' => 'string',
default => $type,
});
}
Expand Down
23 changes: 23 additions & 0 deletions tests/Database/DatabaseSchemaBlueprintIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,29 @@ public function testChangingColumnWithCollationWorks()
$this->assertEquals($expected2, $queries2);
}

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

$blueprint = new Blueprint('users', function ($table) {
$table->char('name', 50)->change();
});

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

$expected = [
'CREATE TEMPORARY TABLE __temp__users AS SELECT name FROM users',
'DROP TABLE users',
'CREATE TABLE users (name CHAR(50) NOT NULL COLLATE BINARY)',
'INSERT INTO users (name) SELECT name FROM __temp__users',
'DROP TABLE __temp__users',
];

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

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

0 comments on commit 5dfafe4

Please sign in to comment.