MediaWiki REL1_37
MWPostgreSqlPlatform.php
Go to the documentation of this file.
1<?php
2
7namespace Wikimedia\Rdbms;
8
9use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
10use Wikimedia\Timestamp\ConvertibleTimestamp;
11
12class MWPostgreSqlPlatform extends PostgreSQL94Platform {
20 public function getDefaultValueDeclarationSQL( $column ) {
21 $type = $column['type'];
22 $default = $column['default'] ?? null;
23
24 if ( $type instanceof TimestampType && $default ) {
25 $timestamp = new ConvertibleTimestamp( $default );
26 $pgTimestamp = $timestamp->getTimestamp( TS_POSTGRES );
27
28 return " DEFAULT '$pgTimestamp' ";
29 }
30
31 return parent::getDefaultValueDeclarationSQL( $column );
32 }
33
38 protected function _getCreateTableSQL( $name, $columns, array $options = [] ) {
39 // phpcs:enable
40 $tableSql = parent::_getCreateTableSQL( $name, $columns, $options );
41 foreach ( $columns as $column ) {
42 if ( $column['type'] instanceof EnumType && $column['fixed'] ) {
43 // PostgreSQL does support ENUM datatype but they need to be
44 // created severally with CREATE TYPE command for each column
45 // as it's not possible to feed the values directly in the
46 // column declaration as it could be done in MySQL.
47 $typeSql = $column['type']->makeEnumTypeSql( $column, $this );
48 array_unshift( $tableSql, $typeSql );
49 }
50 }
51
52 return $tableSql;
53 }
54
58 public function getFloatDeclarationSQL( array $column ) {
59 return 'FLOAT';
60 }
61
65 public function getDateTimeTzTypeDeclarationSQL( array $column ) {
66 return 'TIMESTAMPTZ';
67 }
68}
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.