Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
MWPostgreSqlPlatform | |
0.00% |
0 / 21 |
|
0.00% |
0 / 6 |
210 | |
0.00% |
0 / 1 |
getDefaultValueDeclarationSQL | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
42 | |||
_getCreateTableSQL | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
getBlobTypeDeclarationSQL | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getBinaryTypeDeclarationSQL | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getFloatDeclarationSQL | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getDateTimeTzTypeDeclarationSQL | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Wikimedia\Rdbms; |
4 | |
5 | use Doctrine\DBAL\Platforms\PostgreSQLPlatform; |
6 | use Wikimedia\Timestamp\ConvertibleTimestamp; |
7 | |
8 | class MWPostgreSqlPlatform extends PostgreSQLPlatform { |
9 | /** |
10 | * Handles Postgres unique timestamp format |
11 | * @inheritDoc |
12 | * |
13 | * @param mixed[] $column The column definition array. |
14 | * @return string Postgres specific SQL code portion needed to set a default value. |
15 | */ |
16 | public function getDefaultValueDeclarationSQL( $column ) { |
17 | $type = $column['type']; |
18 | $default = $column['default'] ?? null; |
19 | |
20 | if ( $type instanceof TimestampType && $default ) { |
21 | if ( isset( $column['allowInfinite'] ) && |
22 | $column['allowInfinite'] && |
23 | $default === 'infinity' |
24 | ) { |
25 | $pgTimestamp = $default; |
26 | } else { |
27 | $timestamp = new ConvertibleTimestamp( $default ); |
28 | $pgTimestamp = $timestamp->getTimestamp( TS_POSTGRES ); |
29 | } |
30 | |
31 | return " DEFAULT '$pgTimestamp' "; |
32 | } |
33 | |
34 | return parent::getDefaultValueDeclarationSQL( $column ); |
35 | } |
36 | |
37 | /** |
38 | * @inheritDoc |
39 | * phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
40 | */ |
41 | protected function _getCreateTableSQL( $name, $columns, array $options = [] ) { |
42 | // phpcs:enable |
43 | $tableSql = parent::_getCreateTableSQL( $name, $columns, $options ); |
44 | foreach ( $columns as $column ) { |
45 | if ( $column['type'] instanceof EnumType && $column['fixed'] ) { |
46 | // PostgreSQL does support ENUM datatype but they need to be |
47 | // created severally with CREATE TYPE command for each column |
48 | // as it's not possible to feed the values directly in the |
49 | // column declaration as it could be done in MySQL. |
50 | $typeSql = $column['type']->makeEnumTypeSql( $column, $this ); |
51 | array_unshift( $tableSql, $typeSql ); |
52 | } |
53 | } |
54 | |
55 | return $tableSql; |
56 | } |
57 | |
58 | /** |
59 | * @inheritDoc |
60 | */ |
61 | public function getBlobTypeDeclarationSQL( array $column ) { |
62 | // MySQL goes with varbinary for collation reasons, but postgres can't |
63 | // properly understand BYTEA type and works just fine with TEXT type |
64 | // FIXME: This should be fixed at some point (T257755) |
65 | return 'TEXT'; |
66 | } |
67 | |
68 | /** |
69 | * @inheritDoc |
70 | */ |
71 | public function getBinaryTypeDeclarationSQL( array $column ) { |
72 | // MySQL goes with varbinary for collation reasons, but postgres can't |
73 | // properly understand BYTEA type and works just fine with TEXT type |
74 | // FIXME: This should be fixed at some point (T257755) |
75 | return 'TEXT'; |
76 | } |
77 | |
78 | /** |
79 | * @inheritDoc |
80 | */ |
81 | public function getFloatDeclarationSQL( array $column ) { |
82 | return 'FLOAT'; |
83 | } |
84 | |
85 | /** |
86 | * @inheritDoc |
87 | */ |
88 | public function getDateTimeTzTypeDeclarationSQL( array $column ) { |
89 | return 'TIMESTAMPTZ'; |
90 | } |
91 | } |