Skip to content

Commit 89382ad

Browse files
authored
Merge branch 'master' into upgrade-php
2 parents 45058da + fa81f2a commit 89382ad

File tree

10 files changed

+110
-8
lines changed

10 files changed

+110
-8
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@
4040
},
4141
"require-dev": {
4242
"umbrellio/code-style-php": "^1.0",
43-
"orchestra/testbench": "^3.5|^6.0|^4.0|^7.0",
43+
"orchestra/testbench": "^3.5|^6.0|^4.0|^7.0|^8.0",
4444
"php-coveralls/php-coveralls": "^2.1|^2.7",
45-
"codeception/codeception": "^3.0|^4.0|^5.0.0-RC7|^5.1"
45+
"codeception/codeception": "^3.0|^4.0|^5.0"
46+
"phpunit/phpunit": "^9.6|^10.0|^11.0"
4647
},
4748
"scripts": {
4849
"lint": [

src/.meta.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Schema {
3434
* @method Fluent dropView(string $view)
3535
* @method ColumnDefinition numeric(string $column, ?int $precision = null, ?int $scale = null)
3636
* @method ColumnDefinition tsrange(string $column)
37+
* @method ColumnDefinition tstzrange(string $column)
3738
* @method ColumnDefinition daterange(string $column)
3839
* @method ExcludeDefinition exclude($columns, ?string $index = null)
3940
* @method CheckDefinition check($columns, ?string $index = null)

src/PostgresConnection.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Umbrellio\Postgres\Schema\Subscribers\SchemaAlterTableChangeColumnSubscriber;
1919
use Umbrellio\Postgres\Schema\Types\NumericType;
2020
use Umbrellio\Postgres\Schema\Types\TsRangeType;
21+
use Umbrellio\Postgres\Schema\Types\TsTzRangeType;
2122

2223
class PostgresConnection extends BasePostgresConnection
2324
{
@@ -29,6 +30,7 @@ class PostgresConnection extends BasePostgresConnection
2930

3031
private $initialTypes = [
3132
TsRangeType::TYPE_NAME => TsRangeType::class,
33+
TsTzRangeType::TYPE_NAME => TsTzRangeType::class,
3234
NumericType::TYPE_NAME => NumericType::class,
3335
];
3436

src/Schema/Blueprint.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Umbrellio\Postgres\Schema\Definitions\ViewDefinition;
2020
use Umbrellio\Postgres\Schema\Types\DateRangeType;
2121
use Umbrellio\Postgres\Schema\Types\TsRangeType;
22+
use Umbrellio\Postgres\Schema\Types\TsTzRangeType;
2223

2324
class Blueprint extends BaseBlueprint
2425
{
@@ -148,6 +149,14 @@ public function tsrange(string $column): Fluent
148149
return $this->addColumn(TsRangeType::TYPE_NAME, $column);
149150
}
150151

152+
/**
153+
* @return Fluent|ColumnDefinition
154+
*/
155+
public function tstzrange(string $column): Fluent
156+
{
157+
return $this->addColumn(TsTzRangeType::TYPE_NAME, $column);
158+
}
159+
151160
/**
152161
* @return Fluent|ColumnDefinition
153162
*/

src/Schema/Builder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ public function dropView(string $view): void
2828
$this->build($blueprint);
2929
}
3030

31-
public function hasView(string $view): bool
31+
public function hasView($view): bool
3232
{
3333
return count($this->connection->selectFromWriteConnection($this->grammar->compileViewExists(), [
3434
$this->connection->getConfig()['schema'],
3535
$this->connection->getTablePrefix() . $view,
3636
])) > 0;
3737
}
3838

39-
public function getForeignKeys(string $tableName): array
39+
public function getForeignKeys($tableName): array
4040
{
4141
return $this->connection->selectFromWriteConnection($this->grammar->compileForeignKeysListing($tableName));
4242
}

src/Schema/Grammars/PostgresGrammar.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Umbrellio\Postgres\Schema\Types\DateRangeType;
2020
use Umbrellio\Postgres\Schema\Types\NumericType;
2121
use Umbrellio\Postgres\Schema\Types\TsRangeType;
22+
use Umbrellio\Postgres\Schema\Types\TsTzRangeType;
2223

2324
class PostgresGrammar extends BasePostgresGrammar
2425
{
@@ -122,11 +123,11 @@ protected function typeNumeric(Fluent $column): string
122123
$scale = $column->get('scale');
123124

124125
if ($precision && $scale) {
125-
return "${type}({$precision}, {$scale})";
126+
return "{$type}({$precision}, {$scale})";
126127
}
127128

128129
if ($precision) {
129-
return "${type}({$precision})";
130+
return "{$type}({$precision})";
130131
}
131132

132133
return $type;
@@ -137,6 +138,11 @@ protected function typeTsrange(/** @scrutinizer ignore-unused */ Fluent $column)
137138
return TsRangeType::TYPE_NAME;
138139
}
139140

141+
protected function typeTstzrange(/** @scrutinizer ignore-unused */ Fluent $column): string
142+
{
143+
return TsTzRangeType::TYPE_NAME;
144+
}
145+
140146
protected function typeDaterange(/** @scrutinizer ignore-unused */ Fluent $column): string
141147
{
142148
return DateRangeType::TYPE_NAME;

src/Schema/Subscribers/SchemaAlterTableChangeColumnSubscriber.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\DBAL\Types\IntegerType;
1616
use Illuminate\Database\Query\Expression;
1717
use Illuminate\Support\Collection;
18+
use Umbrellio\Postgres\Schema\Grammars\PostgresGrammar;
1819

1920
final class SchemaAlterTableChangeColumnSubscriber implements EventSubscriber
2021
{
@@ -197,8 +198,9 @@ public function compileAlterColumnType(
197198

198199
public function getDefaultValueDeclarationSQL(AbstractPlatform $platform, Column $column): string
199200
{
200-
if ($column->getDefault() instanceof Expression) {
201-
return ' DEFAULT ' . $column->getDefault();
201+
$defaultValue = $column->getDefault();
202+
if ($defaultValue instanceof Expression) {
203+
return ' DEFAULT ' . $defaultValue->getValue(new PostgresGrammar());
202204
}
203205

204206
return $platform->getDefaultValueDeclarationSQL($column->toArray());

src/Schema/Types/TsTzRangeType.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Umbrellio\Postgres\Schema\Types;
6+
7+
use Doctrine\DBAL\Platforms\AbstractPlatform;
8+
use Doctrine\DBAL\Types\Type;
9+
10+
class TsTzRangeType extends Type
11+
{
12+
public const TYPE_NAME = 'tstzrange';
13+
14+
public function getSQLDeclaration(array $column, AbstractPlatform $platform): string
15+
{
16+
return static::TYPE_NAME;
17+
}
18+
19+
public function getName(): string
20+
{
21+
return self::TYPE_NAME;
22+
}
23+
}

tests/Unit/Schema/Blueprint/PartitionTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ public function addingTsrangeColumn()
103103
$this->assertSameSql('alter table "test_table" add column "foo" tsrange not null');
104104
}
105105

106+
/**
107+
* @test
108+
*/
109+
public function addingTstzrangeColumn()
110+
{
111+
$this->blueprint->tstzrange('foo');
112+
$this->assertSameSql('alter table "test_table" add column "foo" tstzrange not null');
113+
}
114+
106115
/**
107116
* @test
108117
*/
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Umbrellio\Postgres\Unit\Schema\Types;
6+
7+
use Doctrine\DBAL\Platforms\AbstractPlatform;
8+
use Umbrellio\Postgres\Schema\Types\TsTzRangeType;
9+
use Umbrellio\Postgres\Tests\TestCase;
10+
11+
class TsTzRangeTypeTest extends TestCase
12+
{
13+
/**
14+
* @var AbstractPlatform
15+
*/
16+
private $abstractPlatform;
17+
18+
/**
19+
* @var TsRangeType
20+
*/
21+
private $type;
22+
23+
protected function setUp(): void
24+
{
25+
parent::setUp();
26+
27+
$this->type = $this
28+
->getMockBuilder(TsTzRangeType::class)
29+
->disableOriginalConstructor()
30+
->getMockForAbstractClass();
31+
$this->abstractPlatform = $this->getMockForAbstractClass(AbstractPlatform::class);
32+
}
33+
34+
/**
35+
* @test
36+
*/
37+
public function getSQLDeclaration(): void
38+
{
39+
$this->assertSame(TsTzRangeType::TYPE_NAME, $this->type->getSQLDeclaration([], $this->abstractPlatform));
40+
}
41+
42+
/**
43+
* @test
44+
*/
45+
public function getTypeName(): void
46+
{
47+
$this->assertSame(TsTzRangeType::TYPE_NAME, $this->type->getName());
48+
}
49+
}

0 commit comments

Comments
 (0)