MediaWiki  master
DoctrineSchemaBuilder.php
Go to the documentation of this file.
1 <?php
2 namespace Wikimedia\Rdbms;
3 
4 use Doctrine\DBAL\Platforms\AbstractPlatform;
5 use Doctrine\DBAL\Schema\Schema;
6 
12  private $schema;
13  private $platform;
14 
15  const TABLE_PREFIX = '/*_*/';
16 
17  public function __construct( AbstractPlatform $platform ) {
18  $this->schema = new Schema();
19  $this->platform = $platform;
20  }
21 
22  public function addTable( array $schema ) {
23  $table = $this->schema->createTable( self::TABLE_PREFIX . $schema['name'] );
24  foreach ( $schema['columns'] as $column ) {
25  $table->addColumn( $column['name'], $column['type'], $column['options'] );
26  }
27  foreach ( $schema['indexes'] as $index ) {
28  if ( $index['unique'] === true ) {
29  $table->addUniqueIndex( $index['columns'], $index['name'] );
30  } else {
31  $table->addIndex( $index['columns'], $index['name'] );
32  }
33  }
34  $table->setPrimaryKey( $schema['pk'] );
35  $table->addOption( 'table_options', '' );
36  }
37 
38  public function getSql() {
39  return $this->schema->toSql( $this->platform );
40  }
41 }
Wikimedia\Rdbms\DoctrineSchemaBuilder\$schema
$schema
Definition: DoctrineSchemaBuilder.php:12
Wikimedia\Rdbms\DoctrineSchemaBuilder\TABLE_PREFIX
const TABLE_PREFIX
Definition: DoctrineSchemaBuilder.php:15
Wikimedia\Rdbms\DoctrineSchemaBuilder\getSql
getSql()
Definition: DoctrineSchemaBuilder.php:38
Wikimedia\Rdbms
Definition: ChronologyProtector.php:24
Wikimedia\Rdbms\SchemaBuilder
Interface SchemaBuilder that gets a definition and produces SQL based on RDBMS.
Definition: SchemaBuilder.php:10
Wikimedia\Rdbms\DoctrineSchemaBuilder\$platform
$platform
Definition: DoctrineSchemaBuilder.php:13
Wikimedia\Rdbms\DoctrineSchemaBuilder
@experimental @unstable
Definition: DoctrineSchemaBuilder.php:11
Wikimedia\Rdbms\DoctrineSchemaBuilder\__construct
__construct(AbstractPlatform $platform)
Definition: DoctrineSchemaBuilder.php:17
Wikimedia\Rdbms\DoctrineSchemaBuilder\addTable
addTable(array $schema)
An example of $schema value: [ 'name' => 'actor', 'columns' => [ [ 'actor_id', 'bigint',...
Definition: DoctrineSchemaBuilder.php:22