MediaWiki master
DoctrineSchemaChangeBuilder.php
Go to the documentation of this file.
1<?php
2
3namespace Wikimedia\Rdbms;
4
5use Doctrine\DBAL\Platforms\AbstractPlatform;
6use Doctrine\DBAL\Schema\Comparator;
7use Doctrine\DBAL\Schema\Schema;
8
15
16 private $platform;
17
23 public function __construct( AbstractPlatform $platform ) {
24 $this->platform = $platform;
25 }
26
27 private function getTableSchema( array $tableSpec ): Schema {
28 if ( !$tableSpec ) {
29 // Used for not yet created tables.
30 return new Schema();
31 }
32 return $this->addTableToSchema( new Schema(), $tableSpec );
33 }
34
35 public function getSchemaChangeSql( array $schemaChangeSpec ): array {
36 $comparator = new Comparator();
37 $schemaDiff = $comparator->compare(
38 $this->getTableSchema( $schemaChangeSpec['before'] ),
39 $this->getTableSchema( $schemaChangeSpec['after'] )
40 );
41 return $schemaDiff->toSql( $this->platform );
42 }
43}
if(!defined('MW_SETUP_CALLBACK'))
Definition WebStart.php:81
__construct(AbstractPlatform $platform)
A builder object that take abstract schema definition and produces sql to create the tables.
getSchemaChangeSql(array $schemaChangeSpec)
An example of $schema value: [ 'comment' => 'Adding foo field', 'before' => <Before snapshot of the a...
Interface SchemaChangeBuilder that gets a definition and produces ALTER TABLE SQL based on RDBMS.
trait DoctrineAbstractSchemaTrait
Trait for schema spec of doctrine-based abstract schema.