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

[9.x] Support modifying a char column type #41320

Merged
merged 1 commit into from
Mar 3, 2022
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
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