MediaWiki  master
MWPostgreSqlPlatform.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Wikimedia\Rdbms;
4 
5 use Wikimedia\Timestamp\ConvertibleTimestamp;
6 
10 class MWPostgreSqlPlatform extends MWPostgreSqlPlatformCompat {
19  public function getDefaultValueDeclarationSQL( $column ) {
20  $type = $column['type'];
21  $default = $column['default'] ?? null;
22 
23  if ( $type instanceof TimestampType && $default ) {
24  $timestamp = new ConvertibleTimestamp( $default );
25  $pgTimestamp = $timestamp->getTimestamp( TS_POSTGRES );
26 
27  return " DEFAULT '$pgTimestamp' ";
28  }
29 
30  return parent::getDefaultValueDeclarationSQL( $column );
31  }
32 
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 }
Wikimedia\Rdbms\MWPostgreSqlPlatform\getDefaultValueDeclarationSQL
getDefaultValueDeclarationSQL( $column)
Handles Postgres unique timestamp format.
Definition: MWPostgreSqlPlatform.php:19
Wikimedia\Rdbms\MWPostgreSqlPlatform\getFloatDeclarationSQL
getFloatDeclarationSQL(array $column)
Definition: MWPostgreSqlPlatform.php:58
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
Wikimedia\Rdbms\EnumType
Custom handling for ENUM datatype.
Definition: EnumType.php:17
Wikimedia\Rdbms\TimestampType
Handling timestamp edge cases in mediawiki.
Definition: TimestampType.php:12
Wikimedia\Rdbms\MWPostgreSqlPlatform\getDateTimeTzTypeDeclarationSQL
getDateTimeTzTypeDeclarationSQL(array $column)
Definition: MWPostgreSqlPlatform.php:65
Wikimedia\Rdbms\MWPostgreSqlPlatform
Definition: MWPostgreSqlPlatform.php:10
Wikimedia\Rdbms\MWPostgreSqlPlatform\_getCreateTableSQL
_getCreateTableSQL( $name, $columns, array $options=[])
phpcs:disable PSR2.Methods.MethodDeclaration.Underscore
Definition: MWPostgreSqlPlatform.php:38
$type
$type
Definition: testCompression.php:52