MediaWiki REL1_39
MWPostgreSqlPlatform.php
Go to the documentation of this file.
1<?php
2
3namespace Wikimedia\Rdbms;
4
5use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
6use Wikimedia\Timestamp\ConvertibleTimestamp;
7
8class MWPostgreSqlPlatform extends PostgreSQL94Platform {
9
17 public function getDefaultValueDeclarationSQL( $column ) {
18 $type = $column['type'];
19 $default = $column['default'] ?? null;
20
21 if ( $type instanceof TimestampType && $default ) {
22 if ( isset( $column['allowInfinite'] ) &&
23 $column['allowInfinite'] &&
24 $default === 'infinity'
25 ) {
26 $pgTimestamp = $default;
27 } else {
28 $timestamp = new ConvertibleTimestamp( $default );
29 $pgTimestamp = $timestamp->getTimestamp( TS_POSTGRES );
30 }
31
32 return " DEFAULT '$pgTimestamp' ";
33 }
34
35 return parent::getDefaultValueDeclarationSQL( $column );
36 }
37
42 protected function _getCreateTableSQL( $name, $columns, array $options = [] ) {
43 // phpcs:enable
44 $tableSql = parent::_getCreateTableSQL( $name, $columns, $options );
45 foreach ( $columns as $column ) {
46 if ( $column['type'] instanceof EnumType && $column['fixed'] ) {
47 // PostgreSQL does support ENUM datatype but they need to be
48 // created severally with CREATE TYPE command for each column
49 // as it's not possible to feed the values directly in the
50 // column declaration as it could be done in MySQL.
51 $typeSql = $column['type']->makeEnumTypeSql( $column, $this );
52 array_unshift( $tableSql, $typeSql );
53 }
54 }
55
56 return $tableSql;
57 }
58
62 public function getBlobTypeDeclarationSQL( array $column ) {
63 // MySQL goes with varbinary for collation reasons, but postgres can't
64 // properly understand BYTEA type and works just fine with TEXT type
65 // FIXME: This should be fixed at some point (T257755)
66 return 'TEXT';
67 }
68
72 public function getBinaryTypeDeclarationSQL( array $column ) {
73 // MySQL goes with varbinary for collation reasons, but postgres can't
74 // properly understand BYTEA type and works just fine with TEXT type
75 // FIXME: This should be fixed at some point (T257755)
76 return 'TEXT';
77 }
78
82 public function getFloatDeclarationSQL( array $column ) {
83 return 'FLOAT';
84 }
85
89 public function getDateTimeTzTypeDeclarationSQL( array $column ) {
90 return 'TIMESTAMPTZ';
91 }
92}
Custom handling for ENUM datatype.
Definition EnumType.php:17
getDefaultValueDeclarationSQL( $column)
Handles Postgres unique timestamp format .
_getCreateTableSQL( $name, $columns, array $options=[])
phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
Handling timestamp edge cases in mediawiki.