Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit fe88231

Browse files
Merge branch 'defenestrator/master'
2 parents 78e24ab + cdbad58 commit fe88231

File tree

5 files changed

+74
-3
lines changed

5 files changed

+74
-3
lines changed

src/Connection/PostgresConnection.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Dyrynda\Database\Connection;
4+
5+
use Dyrynda\Database\Schema\Grammars\PostgresGrammar;
6+
use Illuminate\Database\PostgresConnection as BasePostgresConnection;
7+
8+
class PostgresConnection extends BasePostgresConnection
9+
{
10+
/**
11+
* Get the default schema grammar instance.
12+
*
13+
* @return \Illuminate\Database\Grammar
14+
*/
15+
protected function getDefaultSchemaGrammar()
16+
{
17+
return $this->withTablePrefix(new PostgresGrammar);
18+
}
19+
}

src/LaravelEfficientUuidServiceProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Database\Schema\Blueprint;
88
use Dyrynda\Database\Connection\MySqlConnection;
99
use Dyrynda\Database\Connection\SQLiteConnection;
10+
use Dyrynda\Database\Connection\PostgresConnection;
1011

1112
class LaravelEfficientUuidServiceProvider extends ServiceProvider
1213
{
@@ -31,6 +32,10 @@ public function register()
3132
return new MySqlConnection($connection, $database, $prefix, $config);
3233
});
3334

35+
Connection::resolverFor('postgres', function ($connection, $database, $prefix, $config) {
36+
return new PostgresConnection($connection, $database, $prefix, $config);
37+
});
38+
3439
Connection::resolverFor('sqlite', function ($connection, $database, $prefix, $config) {
3540
return new SQLiteConnection($connection, $database, $prefix, $config);
3641
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Dyrynda\Database\Schema\Grammars;
4+
5+
use Illuminate\Database\Schema\Grammars\PostgresGrammar as BasePostgresGrammar;
6+
7+
class PostgresGrammar extends BasePostgresGrammar
8+
{
9+
/**
10+
* Create the column definition for a UUID type.
11+
*
12+
* @return string
13+
*/
14+
protected function typeEfficientUuid()
15+
{
16+
return 'bytea';
17+
}
18+
}

src/Schema/Grammars/SQLiteGrammar.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ class SQLiteGrammar extends IlluminateSQLiteGrammar
1010
/**
1111
* Create the column definition for a UUID type.
1212
*
13-
* @param \Illuminate\Support\Fluent $column
14-
*
1513
* @return string
1614
*/
17-
protected function typeEfficientUuid(Fluent $column)
15+
protected function typeEfficientUuid()
1816
{
1917
return 'blob(256)';
2018
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use Mockery as m;
6+
use Illuminate\Database\Connection;
7+
use Illuminate\Database\Schema\Blueprint;
8+
use Dyrynda\Database\Schema\Grammars\PostgresGrammar;
9+
10+
class DatabasePostgresSchemaGrammarTest extends TestCase
11+
{
12+
public function tearDown(): void
13+
{
14+
m::close();
15+
}
16+
17+
public function testAddingUuid()
18+
{
19+
$blueprint = new Blueprint('users', function ($table) {
20+
$table->uuid('foo');
21+
$table->efficientUuid('bar');
22+
});
23+
24+
$connection = m::mock(Connection::class);
25+
26+
$this->assertEquals(
27+
['alter table "users" add column "foo" uuid not null, add column "bar" bytea not null'],
28+
$blueprint->toSql($connection, new PostgresGrammar)
29+
);
30+
}
31+
}

0 commit comments

Comments
 (0)