MediaWiki  master
DoctrineAbstractSchemaTrait.php
Go to the documentation of this file.
1 <?php
20 namespace Wikimedia\Rdbms;
21 
22 use Doctrine\DBAL\Schema\Schema;
23 
30 
31  private $platform;
32 
33  private function addTableToSchema( Schema $schema, array $schemaSpec ) {
34  $prefix = $this->platform->getName() === 'postgresql' ? '' : '/*_*/';
35 
36  $table = $schema->createTable( $prefix . $schemaSpec['name'] );
37  foreach ( $schemaSpec['columns'] as $column ) {
38  $table->addColumn( $column['name'], $column['type'], $column['options'] );
39  }
40 
41  foreach ( $schemaSpec['indexes'] as $index ) {
42  if ( $index['unique'] === true ) {
43  $table->addUniqueIndex( $index['columns'], $index['name'], $index['options'] ?? [] );
44  } else {
45  $table->addIndex( $index['columns'], $index['name'], $index['flags'] ?? [], $index['options'] ?? [] );
46  }
47  }
48 
49  if ( isset( $schemaSpec['pk'] ) ) {
50  $table->setPrimaryKey( $schemaSpec['pk'] );
51  }
52 
53  if ( isset( $schemaSpec['table_options'] ) ) {
54  $table->addOption( 'table_options', implode( ' ', $schemaSpec['table_options'] ) );
55  } else {
56  $table->addOption( 'table_options', '/*$wgDBTableOptions*/' );
57  }
58 
59  return $schema;
60  }
61 }
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
Wikimedia\Rdbms\addTableToSchema
addTableToSchema(Schema $schema, array $schemaSpec)
Definition: DoctrineAbstractSchemaTrait.php:33
Wikimedia\Rdbms\DoctrineAbstractSchemaTrait
trait DoctrineAbstractSchemaTrait
Trait for schema spec of doctrine-based abstract schema.
Definition: DoctrineAbstractSchemaTrait.php:29