Debian Codegraph @

includes/libs/rdbms/dbal/DoctrineAbstractSchemaTrait.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20 namespace Wikimedia\Rdbms;
21
22 use Doctrine\DBAL\Platforms\AbstractPlatform;
23 use Doctrine\DBAL\Schema\Schema;
24
25 /**
26 * Trait for schema spec of doctrine-based abstract schema
27 * @since 1.36
28 * @internal
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 }