Debian Codegraph @

includes/libs/rdbms/dbal/DoctrineSchemaChangeBuilder.php

raw symbols SCIP
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
9 /**
10 * @experimental
11 * @unstable
12 */
13 class DoctrineSchemaChangeBuilder implements SchemaChangeBuilder {
14 use DoctrineAbstractSchemaTrait;
15
16 private AbstractPlatform $platform;
17
18 /**
19 * A builder object that take abstract schema definition and produces sql to create the tables.
20 *
21 * @param AbstractPlatform $platform A Doctrine Platform object, Can be Mysql, Sqlite, etc.
22 */
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 }