Lines 92.59% 25 / 27
Methods 91.66% 22 / 24
Classes 0.00% 0 / 1
Covered by tests of size
Name Lines Methods CRAP
 getType 100.00% 1 / 1 100.00% 1 / 1 1
 integer 100.00% 1 / 1 100.00% 1 / 1 1
 bigInteger 100.00% 1 / 1 100.00% 1 / 1 1
 smallInteger 100.00% 1 / 1 100.00% 1 / 1 1
 varchar 100.00% 1 / 1 100.00% 1 / 1 1
 text 100.00% 1 / 1 100.00% 1 / 1 1
 longText 100.00% 1 / 1 100.00% 1 / 1 1
 blob 100.00% 1 / 1 100.00% 1 / 1 1
 boolean 100.00% 1 / 1 100.00% 1 / 1 1
 timestamp 100.00% 1 / 1 100.00% 1 / 1 1
 date 0.00% 0 / 1 0.00% 0 / 1 2
 char 100.00% 1 / 1 100.00% 1 / 1 1
 currentTimestamp 100.00% 1 / 1 100.00% 1 / 1 1
 currentDate 100.00% 1 / 1 100.00% 1 / 1 1
 autoIncrement 100.00% 1 / 1 100.00% 1 / 1 1
 createTablePrefix 100.00% 2 / 2 100.00% 1 / 1 2
 createTableSuffix 100.00% 1 / 1 100.00% 1 / 1 1
 addColumn 100.00% 1 / 1 100.00% 1 / 1 1
 modifyColumn 100.00% 1 / 1 100.00% 1 / 1 1
 createIndex 100.00% 3 / 3 100.00% 1 / 1 2
 dropIndex 100.00% 1 / 1 100.00% 1 / 1 1
 supportsColumnPositioning 100.00% 1 / 1 100.00% 1 / 1 1
 supportsCombinedAlter 0.00% 0 / 1 0.00% 0 / 1 2
 quoteIdentifier 100.00% 1 / 1 100.00% 1 / 1 1
24class PostgresDialect implements DialectInterface
25{
26    public function getType(): string
27    {
28        return 'pgsql';
29    }
30
31    public function integer(): string
32    {
33        return 'INTEGER';
34    }
35
36    public function bigInteger(): string
37    {
38        return 'BIGINT';
39    }
40
41    public function smallInteger(): string
42    {
43        return 'SMALLINT';
44    }
45
46    public function varchar(int $length): string
47    {
48        return "VARCHAR({$length})";
49    }
50
51    public function text(): string
52    {
53        return 'TEXT';
54    }
55
56    public function longText(): string
57    {
58        return 'TEXT';
59    }
60
61    public function blob(): string
62    {
63        return 'BYTEA';
64    }
65
66    public function boolean(): string
67    {
68        return 'SMALLINT';
69    }
70
71    public function timestamp(): string
72    {
73        return 'TIMESTAMP';
74    }
75
76    public function date(): string
77    {
78        return 'DATE';
79    }
80
81    public function char(int $length): string
82    {
83        return "CHAR({$length})";
84    }
85
86    public function currentTimestamp(): string
87    {
88        return 'CURRENT_TIMESTAMP';
89    }
90
91    public function currentDate(): string
92    {
93        return 'CURRENT_DATE';
94    }
95
96    public function autoIncrement(string $columnName): string
97    {
98        return "{$columnName} SERIAL NOT NULL";
99    }
100
101    public function createTablePrefix(string $tableName, bool $ifNotExists = false): string
102    {
103        $exists = $ifNotExists ? 'IF NOT EXISTS ' : '';
104        return "CREATE TABLE {$exists}{$tableName}";
105    }
106
107    public function createTableSuffix(): string
108    {
109        return '';
110    }
111
112    public function addColumn(string $tableName, string $columnName, string $type, ?string $after = null): string
113    {
114        // PostgreSQL doesn't support AFTER clause
115        return "ALTER TABLE {$tableName} ADD COLUMN {$columnName} {$type}";
116    }
117
118    public function modifyColumn(string $tableName, string $columnName, string $newType): string
119    {
120        return "ALTER TABLE {$tableName} ALTER COLUMN {$columnName} TYPE {$newType}";
121    }
122
123    /**
124     * @param string[] $columns
125     */
126    public function createIndex(string $indexName, string $tableName, array $columns, bool $ifNotExists = false): string
127    {
128        $columnList = implode(', ', $columns);
129        $exists = $ifNotExists ? 'IF NOT EXISTS ' : '';
130        return "CREATE INDEX {$exists}{$indexName} ON {$tableName} ({$columnList})";
131    }
132
133    public function dropIndex(string $indexName, string $tableName): string
134    {
135        return "DROP INDEX {$indexName}";
136    }
137
138    public function supportsColumnPositioning(): bool
139    {
140        return false;
141    }
142
143    public function supportsCombinedAlter(): bool
144    {
145        return false;
146    }
147
148    public function quoteIdentifier(string $identifier): string
149    {
150        return '"' . str_replace(search: '"', replace: '""', subject: $identifier) . '"';
151    }
152}