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

[11.x] Add column type for native UUID #50192

Closed
wants to merge 7 commits into from
Closed
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
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,17 @@ public function foreignUuid($column)
]));
}

/**
* Create a new native UUID column on the table.
*
* @param string $column
* @return \Illuminate\Database\Schema\ColumnDefinition
*/
public function nativeUuid($column = 'uuid')
{
return $this->addColumn('nativeUuid', $column);
}

/**
* Create a new ULID column on the table.
*
Expand Down
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@ protected function getType(Fluent $column)
return $this->{'type'.ucfirst($column->type)}($column);
}

/**
* Create the column definition for a native uuid type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeNativeUuid(Fluent $column)
{
throw new RuntimeException('This database driver does not support the native UUID type.');
}

/**
* Create the column definition for a generated, computed column type.
*
Expand Down
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/MariaDbGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ public function compileRenameColumn(Blueprint $blueprint, Fluent $command, Conne
return parent::compileRenameColumn($blueprint, $command, $connection);
}

/**
* Create the column definition for a native uuid type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeNativeUuid(Fluent $column)
{
return 'uuid';
}

/**
* Create the column definition for a spatial Geometry type.
*
Expand Down
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,17 @@ protected function typeUuid(Fluent $column)
return 'uuid';
}

/**
* Create the column definition for a native uuid type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeNativeUuid(Fluent $column)
{
return $this->typeUuid($column);
}

/**
* Create the column definition for an IP address type.
*
Expand Down
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/SqlServerGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,17 @@ protected function typeUuid(Fluent $column)
return 'uniqueidentifier';
}

/**
* Create the column definition for a native uuid type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeNativeUuid(Fluent $column)
{
return $this->typeUuid($column);
}

/**
* Create the column definition for an IP address type.
*
Expand Down
10 changes: 10 additions & 0 deletions tests/Database/DatabaseMariaDbSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,16 @@ public function testAddingForeignUuid()
], $statements);
}

public function testAddingNativeUuid()
{
$blueprint = new Blueprint('users');
$blueprint->nativeUuid('foo');
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

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

public function testAddingIpAddress()
{
$blueprint = new Blueprint('users');
Expand Down
11 changes: 11 additions & 0 deletions tests/Database/DatabaseMySqlSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Illuminate\Tests\Database\Fixtures\Enums\Foo;
use Mockery as m;
use PHPUnit\Framework\TestCase;
use RuntimeException;

class DatabaseMySqlSchemaGrammarTest extends TestCase
{
Expand Down Expand Up @@ -1124,6 +1125,16 @@ public function testAddingForeignUuid()
], $statements);
}

public function testAddingNativeUuid()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('This database driver does not support the native UUID type.');

$blueprint = new Blueprint('users');
$blueprint->nativeUuid('foo');
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
}

public function testAddingIpAddress()
{
$blueprint = new Blueprint('users');
Expand Down
10 changes: 10 additions & 0 deletions tests/Database/DatabasePostgresSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,16 @@ public function testAddingForeignUuid()
], $statements);
}

public function testAddingNativeUuid()
{
$blueprint = new Blueprint('users');
$blueprint->nativeUuid('foo');
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertSame('alter table "users" add column "foo" uuid not null', $statements[0]);
}

public function testAddingGeneratedAs()
{
$blueprint = new Blueprint('users');
Expand Down
10 changes: 10 additions & 0 deletions tests/Database/DatabaseSQLiteSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,16 @@ public function testAddingForeignUuid()
], $statements);
}

public function testAddingNativeUuid()
{
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('This database driver does not support the native UUID type.');

$blueprint = new Blueprint('users');
$blueprint->nativeUuid('foo');
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());
}

public function testAddingIpAddress()
{
$blueprint = new Blueprint('users');
Expand Down
10 changes: 10 additions & 0 deletions tests/Database/DatabaseSqlServerSchemaGrammarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,16 @@ public function testAddingForeignUuid()
], $statements);
}

public function testAddingNativeUuid()
{
$blueprint = new Blueprint('users');
$blueprint->nativeUuid('foo');
$statements = $blueprint->toSql($this->getConnection(), $this->getGrammar());

$this->assertCount(1, $statements);
$this->assertSame('alter table "users" add "foo" uniqueidentifier not null', $statements[0]);
}

public function testAddingIpAddress()
{
$blueprint = new Blueprint('users');
Expand Down
Loading