Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SchemaDiff::$fromSchema #5676

Merged
merged 1 commit into from
Sep 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ the name of the object as a separate parameter. The name of the passed index or
The `AbstractPlatform::canEmulateSchemas()` method and the schema emulation implemented in the SQLite platform
have been removed.

## BC BREAK: removed `SchemaDiff` reference to the original schema.

The `SchemaDiff` class no longer accepts or exposes a reference to the original schema.

## BC BREAK: Changes in the `ColumnDiff` class

1. The `$fromColumn` parameter of the `ColumnDiff` constructor has been made required.
Expand Down
4 changes: 0 additions & 4 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
</DeprecatedMethod>
<DeprecatedProperty>
<errorLevel type="suppress">
<!--
TODO: remove in 4.0.0
-->
<referencedProperty name="Doctrine\DBAL\Schema\SchemaDiff::$fromSchema"/>
<!--
TODO: remove in 4.0.0
-->
Expand Down
3 changes: 1 addition & 2 deletions src/Schema/Comparator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public function __construct(private readonly AbstractPlatform $platform)
*/
public function compareSchemas(Schema $fromSchema, Schema $toSchema): SchemaDiff
{
$diff = new SchemaDiff();
$diff->fromSchema = $fromSchema;
$diff = new SchemaDiff();

/** @var array<string,list<array{ForeignKeyConstraint,string}>> $foreignKeysToTable */
$foreignKeysToTable = [];
Expand Down
7 changes: 0 additions & 7 deletions src/Schema/SchemaDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

/**
* Differences between two schemas.
*
* The object contains the operations to change the schema stored in $fromSchema
* to a target schema.
*/
class SchemaDiff
{
Expand Down Expand Up @@ -60,10 +57,6 @@ public function __construct(
public array $newTables = [],
public array $changedTables = [],
public array $removedTables = [],
/**
* @deprecated
*/
public ?Schema $fromSchema = null,
) {
}

Expand Down
57 changes: 21 additions & 36 deletions tests/Schema/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ public function testCompareSame1(): void
),
]);

$expected = new SchemaDiff();
$expected->fromSchema = $schema1;
self::assertEquals($expected, $this->comparator->compareSchemas($schema1, $schema2));
self::assertEquals(new SchemaDiff(), $this->comparator->compareSchemas($schema1, $schema2));
}

public function testCompareSame2(): void
Expand All @@ -70,9 +68,7 @@ public function testCompareSame2(): void
),
]);

$expected = new SchemaDiff();
$expected->fromSchema = $schema1;
self::assertEquals($expected, $this->comparator->compareSchemas($schema1, $schema2));
self::assertEquals(new SchemaDiff(), $this->comparator->compareSchemas($schema1, $schema2));
}

public function testCompareMissingTable(): void
Expand All @@ -85,7 +81,7 @@ public function testCompareMissingTable(): void
$schema1 = new Schema([$table], [], $schemaConfig);
$schema2 = new Schema([], [], $schemaConfig);

$expected = new SchemaDiff([], [], ['bugdb' => $table], $schema1);
$expected = new SchemaDiff([], [], ['bugdb' => $table]);

self::assertEquals($expected, $this->comparator->compareSchemas($schema1, $schema2));
}
Expand All @@ -100,7 +96,7 @@ public function testCompareNewTable(): void
$schema1 = new Schema([], [], $schemaConfig);
$schema2 = new Schema([$table], [], $schemaConfig);

$expected = new SchemaDiff(['bugdb' => $table], [], [], $schema1);
$expected = new SchemaDiff(['bugdb' => $table], [], []);

self::assertEquals($expected, $this->comparator->compareSchemas($schema1, $schema2));
}
Expand Down Expand Up @@ -136,7 +132,7 @@ public function testCompareMissingField(): void
),
]);

$expected = new SchemaDiff(
$expected = new SchemaDiff(
[],
[
'bugdb' => new TableDiff(
Expand All @@ -147,7 +143,7 @@ public function testCompareMissingField(): void
),
],
);
$expected->fromSchema = $schema1;

$expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb');

self::assertEquals($expected, $this->comparator->compareSchemas($schema1, $schema2));
Expand All @@ -173,7 +169,7 @@ public function testCompareNewField(): void
),
]);

$expected = new SchemaDiff(
$expected = new SchemaDiff(
[],
[
'bugdb' => new TableDiff(
Expand All @@ -184,7 +180,7 @@ public function testCompareNewField(): void
),
],
);
$expected->fromSchema = $schema1;

$expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb');

self::assertEquals($expected, $this->comparator->compareSchemas($schema1, $schema2));
Expand Down Expand Up @@ -281,7 +277,7 @@ public function testCompareRemovedIndex(): void
),
]);

$expected = new SchemaDiff(
$expected = new SchemaDiff(
[],
[
'bugdb' => new TableDiff(
Expand All @@ -301,7 +297,7 @@ public function testCompareRemovedIndex(): void
),
],
);
$expected->fromSchema = $schema1;

$expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb');

self::assertEquals($expected, $this->comparator->compareSchemas($schema1, $schema2));
Expand Down Expand Up @@ -335,7 +331,7 @@ public function testCompareNewIndex(): void
),
]);

$expected = new SchemaDiff(
$expected = new SchemaDiff(
[],
[
'bugdb' => new TableDiff(
Expand All @@ -353,7 +349,7 @@ public function testCompareNewIndex(): void
),
],
);
$expected->fromSchema = $schema1;

$expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb');

self::assertEquals($expected, $this->comparator->compareSchemas($schema1, $schema2));
Expand Down Expand Up @@ -394,7 +390,7 @@ public function testCompareChangedIndex(): void
),
]);

$expected = new SchemaDiff(
$expected = new SchemaDiff(
[],
[
'bugdb' => new TableDiff(
Expand All @@ -416,7 +412,7 @@ public function testCompareChangedIndex(): void
),
],
);
$expected->fromSchema = $schema1;

$expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb');

self::assertEquals($expected, $this->comparator->compareSchemas($schema1, $schema2));
Expand Down Expand Up @@ -449,7 +445,7 @@ public function testCompareChangedIndexFieldPositions(): void
),
]);

$expected = new SchemaDiff(
$expected = new SchemaDiff(
[],
[
'bugdb' => new TableDiff(
Expand All @@ -464,7 +460,7 @@ public function testCompareChangedIndexFieldPositions(): void
),
],
);
$expected->fromSchema = $schema1;

$expected->changedTables['bugdb']->fromTable = $schema1->getTable('bugdb');

self::assertEquals($expected, $this->comparator->compareSchemas($schema1, $schema2));
Expand Down Expand Up @@ -820,8 +816,7 @@ public function testFqnSchemaComparison(): void
$newSchema = new Schema([], [], $config);
$newSchema->createTable('foo.bar');

$expected = new SchemaDiff();
$expected->fromSchema = $oldSchema;
$expected = new SchemaDiff();

self::assertEquals($expected, $this->comparator->compareSchemas($oldSchema, $newSchema));
}
Expand All @@ -841,7 +836,6 @@ public function testNamespacesComparison(): void
$newSchema->createTable('war.tab');

$expected = new SchemaDiff();
$expected->fromSchema = $oldSchema;
$expected->newNamespaces = ['bar' => 'bar', 'baz' => 'baz'];

$diff = $this->comparator->compareSchemas($oldSchema, $newSchema);
Expand All @@ -861,10 +855,7 @@ public function testFqnSchemaComparisonDifferentSchemaNameButSameTableNoDiff():
$newSchema = new Schema();
$newSchema->createTable('bar');

$expected = new SchemaDiff();
$expected->fromSchema = $oldSchema;

self::assertEquals($expected, $this->comparator->compareSchemas($oldSchema, $newSchema));
self::assertEquals(new SchemaDiff(), $this->comparator->compareSchemas($oldSchema, $newSchema));
}

public function testFqnSchemaComparisonNoSchemaSame(): void
Expand All @@ -877,10 +868,7 @@ public function testFqnSchemaComparisonNoSchemaSame(): void
$newSchema = new Schema();
$newSchema->createTable('bar');

$expected = new SchemaDiff();
$expected->fromSchema = $oldSchema;

self::assertEquals($expected, $this->comparator->compareSchemas($oldSchema, $newSchema));
self::assertEquals(new SchemaDiff(), $this->comparator->compareSchemas($oldSchema, $newSchema));
}

public function testAutoIncrementSequences(): void
Expand Down Expand Up @@ -971,8 +959,7 @@ public function testCompareChangedColumn(): void
$table = $newSchema->createTable('foo');
$table->addColumn('id', 'string', ['length' => 32]);

$expected = new SchemaDiff();
$expected->fromSchema = $oldSchema;
$expected = new SchemaDiff();

$tableDiff = $expected->changedTables['foo'] = new TableDiff('foo');
$tableDiff->fromTable = $tableFoo;
Expand All @@ -996,8 +983,7 @@ public function testCompareChangedBinaryColumn(): void
$table = $newSchema->createTable('foo');
$table->addColumn('id', 'binary', ['length' => 42, 'fixed' => true]);

$expected = new SchemaDiff();
$expected->fromSchema = $oldSchema;
$expected = new SchemaDiff();

$tableDiff = $expected->changedTables['foo'] = new TableDiff('foo');
$tableDiff->fromTable = $tableFoo;
Expand Down Expand Up @@ -1058,7 +1044,6 @@ public function testComparesNamespaces(): void
->willReturnOnConsecutiveCalls(false, true);

$expected = new SchemaDiff();
$expected->fromSchema = $fromSchema;
$expected->newNamespaces = ['baz' => 'baz'];
$expected->removedNamespaces = ['foo' => 'foo'];

Expand Down