• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

umbrellio / laravel-pg-extensions / 8927489636

02 May 2024 04:49PM UTC coverage: 92.258%. First build
8927489636

push

github

web-flow
Dump php version to 8.3 (#88)

* dump php version to 8.3

2 of 5 new or added lines in 2 files covered. (40.0%)

286 of 310 relevant lines covered (92.26%)

37.02 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.43
/src/Schema/Blueprint.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Umbrellio\Postgres\Schema;
6

7
use Doctrine\DBAL\DriverManager;
8
use Illuminate\Database\Schema\Blueprint as BaseBlueprint;
9
use Illuminate\Database\Schema\ColumnDefinition;
10
use Illuminate\Support\Facades\Schema;
11
use Illuminate\Support\Fluent;
12
use Umbrellio\Postgres\Schema\Builders\Constraints\Check\CheckBuilder;
13
use Umbrellio\Postgres\Schema\Builders\Constraints\Exclude\ExcludeBuilder;
14
use Umbrellio\Postgres\Schema\Builders\Indexes\Unique\UniqueBuilder;
15
use Umbrellio\Postgres\Schema\Definitions\AttachPartitionDefinition;
16
use Umbrellio\Postgres\Schema\Definitions\CheckDefinition;
17
use Umbrellio\Postgres\Schema\Definitions\ExcludeDefinition;
18
use Umbrellio\Postgres\Schema\Definitions\LikeDefinition;
19
use Umbrellio\Postgres\Schema\Definitions\UniqueDefinition;
20
use Umbrellio\Postgres\Schema\Definitions\ViewDefinition;
21
use Umbrellio\Postgres\Schema\Types\DateRangeType;
22
use Umbrellio\Postgres\Schema\Types\TsRangeType;
23
use Umbrellio\Postgres\Schema\Types\TsTzRangeType;
24

25
class Blueprint extends BaseBlueprint
26
{
27
    protected $commands = [];
28

29
    /**
30
     * @return AttachPartitionDefinition|Fluent
31
     */
32
    public function attachPartition(string $partition): Fluent
33
    {
34
        return $this->addCommand('attachPartition', compact('partition'));
20✔
35
    }
36

37
    public function detachPartition(string $partition): void
38
    {
39
        $this->addCommand('detachPartition', compact('partition'));
5✔
40
    }
41

42
    /**
43
     * @return LikeDefinition|Fluent
44
     */
45
    public function like(string $table): Fluent
46
    {
47
        return $this->addCommand('like', compact('table'));
×
48
    }
49

50
    public function ifNotExists(): Fluent
51
    {
52
        return $this->addCommand('ifNotExists');
×
53
    }
54

55
    /**
56
     * @param array|string $columns
57
     * @return UniqueDefinition|UniqueBuilder
58
     */
59
    public function uniquePartial($columns, ?string $index = null, ?string $algorithm = null): Fluent
60
    {
61
        $columns = (array) $columns;
65✔
62

63
        $index = $index ?: $this->createIndexName('unique', $columns);
65✔
64

65
        return $this->addExtendedCommand(
65✔
66
            UniqueBuilder::class,
65✔
67
            'uniquePartial',
65✔
68
            compact('columns', 'index', 'algorithm')
65✔
69
        );
65✔
70
    }
71

72
    public function dropUniquePartial($index): Fluent
73
    {
74
        return $this->dropIndexCommand('dropIndex', 'unique', $index);
60✔
75
    }
76

77
    /**
78
     * @param array|string $columns
79
     * @return ExcludeDefinition|ExcludeBuilder
80
     */
81
    public function exclude($columns, ?string $index = null): Fluent
82
    {
83
        $columns = (array) $columns;
30✔
84

85
        $index = $index ?: $this->createIndexName('excl', $columns);
30✔
86

87
        return $this->addExtendedCommand(ExcludeBuilder::class, 'exclude', compact('columns', 'index'));
30✔
88
    }
89

90
    /**
91
     * @param array|string $columns
92
     * @return CheckDefinition|CheckBuilder
93
     */
94
    public function check($columns, ?string $index = null): Fluent
95
    {
96
        $columns = (array) $columns;
15✔
97

98
        $index = $index ?: $this->createIndexName('chk', $columns);
15✔
99

100
        return $this->addExtendedCommand(CheckBuilder::class, 'check', compact('columns', 'index'));
15✔
101
    }
102

103
    public function dropExclude($index): Fluent
104
    {
105
        return $this->dropIndexCommand('dropUnique', 'excl', $index);
5✔
106
    }
107

108
    public function dropCheck($index): Fluent
109
    {
110
        return $this->dropIndexCommand('dropUnique', 'chk', $index);
5✔
111
    }
112

113
    public function hasIndex($index, bool $unique = false): bool
114
    {
115
        if (is_array($index)) {
×
116
            $index = $this->createIndexName($unique === false ? 'index' : 'unique', $index);
×
117
        }
118

119
        return array_key_exists($index, $this->getSchemaManager()->listTableIndexes($this->getTable()));
×
120
    }
121

122
    /**
123
     * @return ViewDefinition|Fluent
124
     */
125
    public function createView(string $view, string $select, bool $materialize = false): Fluent
126
    {
127
        return $this->addCommand('createView', compact('view', 'select', 'materialize'));
×
128
    }
129

130
    public function dropView(string $view): Fluent
131
    {
132
        return $this->addCommand('dropView', compact('view'));
×
133
    }
134

135
    /**
136
     * Almost like 'decimal' type, but can be with variable precision (by default)
137
     *
138
     * @return Fluent|ColumnDefinition
139
     */
140
    public function numeric(string $column, ?int $precision = null, ?int $scale = null): Fluent
141
    {
142
        return $this->addColumn('numeric', $column, compact('precision', 'scale'));
15✔
143
    }
144

145
    /**
146
     * @return Fluent|ColumnDefinition
147
     */
148
    public function tsrange(string $column): Fluent
149
    {
150
        return $this->addColumn(TsRangeType::TYPE_NAME, $column);
5✔
151
    }
152

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

161
    /**
162
     * @return Fluent|ColumnDefinition
163
     */
164
    public function daterange(string $column): Fluent
165
    {
166
        return $this->addColumn(DateRangeType::TYPE_NAME, $column);
5✔
167
    }
168

169
    protected function getSchemaManager()
170
    {
NEW
171
        $connection = Schema::getConnection();
×
NEW
172
        $doctrineConnection = DriverManager::getConnection($connection->getConfig());
×
NEW
173
        return $doctrineConnection->getSchemaManager();
×
174
    }
175

176
    private function addExtendedCommand(string $fluent, string $name, array $parameters = []): Fluent
177
    {
178
        $command = new $fluent(array_merge(compact('name'), $parameters));
110✔
179
        $this->commands[] = $command;
110✔
180
        return $command;
110✔
181
    }
182
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc