Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
DoctrineSchemaChangeBuilder | |
0.00% |
0 / 10 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTableSchema | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getSchemaChangeSql | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 |
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 $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 | } |