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