Skip to content

Commit 8158e29

Browse files
authored
use char(36) for uuid type on MariaDB < 10.7.0 (#55197)
1 parent b5a8ea6 commit 8158e29

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public function compileRenameColumn(Blueprint $blueprint, Fluent $command)
3131
*/
3232
protected function typeUuid(Fluent $column)
3333
{
34+
if (version_compare($this->connection->getServerVersion(), '10.7.0', '<')) {
35+
return 'char(36)';
36+
}
37+
3438
return 'uuid';
3539
}
3640

tests/Database/DatabaseMariaDbSchemaGrammarTest.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function testBasicCreateTable()
5353

5454
$conn = $this->getConnection();
5555
$conn->shouldReceive('getConfig')->andReturn(null);
56+
$conn->shouldReceive('getServerVersion')->andReturn('10.7.0');
5657

5758
$blueprint = new Blueprint($conn, 'users');
5859
$blueprint->create();
@@ -1118,17 +1119,36 @@ public function testAddingBinary()
11181119

11191120
public function testAddingUuid()
11201121
{
1121-
$blueprint = new Blueprint($this->getConnection(), 'users');
1122+
$conn = $this->getConnection();
1123+
$conn->shouldReceive('getServerVersion')->andReturn('10.7.0');
1124+
1125+
$blueprint = new Blueprint($conn, 'users');
11221126
$blueprint->uuid('foo');
11231127
$statements = $blueprint->toSql();
11241128

11251129
$this->assertCount(1, $statements);
11261130
$this->assertSame('alter table `users` add `foo` uuid not null', $statements[0]);
11271131
}
11281132

1133+
public function testAddingUuidOn106()
1134+
{
1135+
$conn = $this->getConnection();
1136+
$conn->shouldReceive('getServerVersion')->andReturn('10.6.21');
1137+
1138+
$blueprint = new Blueprint($conn, 'users');
1139+
$blueprint->uuid('foo');
1140+
$statements = $blueprint->toSql();
1141+
1142+
$this->assertCount(1, $statements);
1143+
$this->assertSame('alter table `users` add `foo` char(36) not null', $statements[0]);
1144+
}
1145+
11291146
public function testAddingUuidDefaultsColumnName()
11301147
{
1131-
$blueprint = new Blueprint($this->getConnection(), 'users');
1148+
$conn = $this->getConnection();
1149+
$conn->shouldReceive('getServerVersion')->andReturn('10.7.0');
1150+
1151+
$blueprint = new Blueprint($conn, 'users');
11321152
$blueprint->uuid();
11331153
$statements = $blueprint->toSql();
11341154

@@ -1138,7 +1158,10 @@ public function testAddingUuidDefaultsColumnName()
11381158

11391159
public function testAddingForeignUuid()
11401160
{
1141-
$blueprint = new Blueprint($this->getConnection(), 'users');
1161+
$conn = $this->getConnection();
1162+
$conn->shouldReceive('getServerVersion')->andReturn('10.7.0');
1163+
1164+
$blueprint = new Blueprint($conn, 'users');
11421165
$foreignUuid = $blueprint->foreignUuid('foo');
11431166
$blueprint->foreignUuid('company_id')->constrained();
11441167
$blueprint->foreignUuid('laravel_idea_id')->constrained();

0 commit comments

Comments
 (0)