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 
29 trait DoctrineAbstractSchemaTrait {
30  private function addTableToSchema( Schema $schema, array $schemaSpec ) {
31  $table = $schema->createTable( '/*_*/' . $schemaSpec['name'] );
32  foreach ( $schemaSpec['columns'] as $column ) {
33  $table->addColumn( $column['name'], $column['type'], $column['options'] );
34  }
35 
36  foreach ( $schemaSpec['indexes'] as $index ) {
37  if ( $index['unique'] === true ) {
38  $table->addUniqueIndex( $index['columns'], $index['name'], $index['options'] ?? [] );
39  } else {
40  $table->addIndex( $index['columns'], $index['name'], $index['flags'] ?? [], $index['options'] ?? [] );
41  }
42  }
43 
44  if ( isset( $schemaSpec['pk'] ) ) {
45  $table->setPrimaryKey( $schemaSpec['pk'] );
46  }
47 
48  if ( isset( $schemaSpec['options'] )
49  && isset( $schemaSpec['options'][0]['table_options'] )
50  ) {
51  $table->addOption( 'table_options', $schemaSpec['options'][0]['table_options'] );
52  } else {
53  $table->addOption( 'table_options', '/*$wgDBTableOptions*/' );
54  }
55 
56  return $schema;
57  }
58 }
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24