MediaWiki REL1_35
DoctrineSchemaBuilder.php
Go to the documentation of this file.
1<?php
2
3namespace Wikimedia\Rdbms;
4
5use Doctrine\DBAL\Platforms\AbstractPlatform;
6use Doctrine\DBAL\Schema\Schema;
7
13 private $schema;
14 private $platform;
15
16 public const TABLE_PREFIX = '/*_*/';
17
23 public function __construct( AbstractPlatform $platform ) {
24 $this->schema = new Schema();
25 $this->platform = $platform;
26 }
27
31 public function addTable( array $schema ) {
32 $table = $this->schema->createTable( self::TABLE_PREFIX . $schema['name'] );
33 foreach ( $schema['columns'] as $column ) {
34 $table->addColumn( $column['name'], $column['type'], $column['options'] );
35 }
36 foreach ( $schema['indexes'] as $index ) {
37 if ( $index['unique'] === true ) {
38 $table->addUniqueIndex( $index['columns'], $index['name'] );
39 } else {
40 $table->addIndex( $index['columns'], $index['name'] );
41 }
42 }
43 $table->setPrimaryKey( $schema['pk'] );
44 $table->addOption( 'table_options', '/*$wgDBTableOptions*/' );
45 }
46
50 public function getSql() {
51 return $this->schema->toSql( $this->platform );
52 }
53}
__construct(AbstractPlatform $platform)
A builder object that take abstract schema definition and produces sql to create the tables.
addTable(array $schema)
An example of $schema value: [ 'name' => 'actor', 'columns' => [ [ 'actor_id', 'bigint',...
Interface SchemaBuilder that gets a definition and produces SQL based on RDBMS.