| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
namespace Wikimedia\Rdbms; |
| 21 |
|
| 22 |
use Doctrine\DBAL\Platforms\AbstractPlatform; |
| 23 |
use Doctrine\DBAL\Schema\Schema; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
trait DoctrineAbstractSchemaTrait { |
| 31 |
|
| 32 |
private AbstractPlatform $platform; |
| 33 |
|
| 34 |
private function addTableToSchema( Schema $schema, array $schemaSpec ) { |
| 35 |
$prefix = $this->platform->getName() === 'postgresql' ? '' : '/*_*/'; |
| 36 |
|
| 37 |
$table = $schema->createTable( $prefix . $schemaSpec['name'] ); |
| 38 |
foreach ( $schemaSpec['columns'] as $column ) { |
| 39 |
$table->addColumn( $column['name'], $column['type'], $column['options'] ); |
| 40 |
} |
| 41 |
|
| 42 |
foreach ( $schemaSpec['indexes'] as $index ) { |
| 43 |
if ( $index['unique'] === true ) { |
| 44 |
$table->addUniqueIndex( $index['columns'], $index['name'], $index['options'] ?? [] ); |
| 45 |
} else { |
| 46 |
$table->addIndex( $index['columns'], $index['name'], $index['flags'] ?? [], $index['options'] ?? [] ); |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
if ( isset( $schemaSpec['pk'] ) && $schemaSpec['pk'] !== [] ) { |
| 51 |
$table->setPrimaryKey( $schemaSpec['pk'] ); |
| 52 |
} |
| 53 |
|
| 54 |
if ( isset( $schemaSpec['table_options'] ) ) { |
| 55 |
$table->addOption( 'table_options', implode( ' ', $schemaSpec['table_options'] ) ); |
| 56 |
} else { |
| 57 |
$table->addOption( 'table_options', '/*$wgDBTableOptions*/' ); |
| 58 |
} |
| 59 |
|
| 60 |
return $schema; |
| 61 |
} |
| 62 |
} |