MediaWiki REL1_40
DoctrineAbstractSchemaTrait.php
Go to the documentation of this file.
1<?php
20namespace Wikimedia\Rdbms;
21
22use 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'] ) && $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}
trait DoctrineAbstractSchemaTrait
Trait for schema spec of doctrine-based abstract schema.