| 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 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 39 |
|
| 40 |
|
| 41 |
protected function _getCreateTableSQL( $name, $columns, array $options = [] ) { |
| 42 |
|
| 43 |
$tableSql = parent::_getCreateTableSQL( $name, $columns, $options ); |
| 44 |
foreach ( $columns as $column ) { |
| 45 |
if ( $column['type'] instanceof EnumType && $column['fixed'] ) { |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
$typeSql = $column['type']->makeEnumTypeSql( $column, $this ); |
| 51 |
array_unshift( $tableSql, $typeSql ); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
return $tableSql; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public function getBlobTypeDeclarationSQL( array $column ) { |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
return 'TEXT'; |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public function getBinaryTypeDeclarationSQL( array $column ) { |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
return 'TEXT'; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public function getFloatDeclarationSQL( array $column ) { |
| 82 |
return 'FLOAT'; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
public function getDateTimeTzTypeDeclarationSQL( array $column ) { |
| 89 |
return 'TIMESTAMPTZ'; |
| 90 |
} |
| 91 |
} |