MediaWiki master
DoctrineAbstractSchemaTrait.php
Go to the documentation of this file.
1<?php
20namespace Wikimedia\Rdbms;
21
22use Doctrine\DBAL\Platforms\AbstractPlatform;
23use Doctrine\DBAL\Schema\Schema;
24
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}
trait DoctrineAbstractSchemaTrait
Trait for schema spec of doctrine-based abstract schema.