Skip to content

Commit a8d12d7

Browse files
committed
Add SchemaDiff::isEmpty()
1 parent 9083d77 commit a8d12d7

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Schema/SchemaDiff.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Doctrine\Deprecations\Deprecation;
77

88
use function array_merge;
9+
use function count;
910

1011
/**
1112
* Differences between two schemas.
@@ -179,6 +180,21 @@ public function getDroppedSequences(): array
179180
return $this->removedSequences;
180181
}
181182

183+
/**
184+
* Returns whether the diff is empty (contains no changes).
185+
*/
186+
public function isEmpty(): bool
187+
{
188+
return count($this->newNamespaces) === 0
189+
&& count($this->removedNamespaces) === 0
190+
&& count($this->newTables) === 0
191+
&& count($this->changedTables) === 0
192+
&& count($this->removedTables) === 0
193+
&& count($this->newSequences) === 0
194+
&& count($this->changedSequences) === 0
195+
&& count($this->removedSequences) === 0;
196+
}
197+
182198
/**
183199
* The to save sql mode ensures that the following things don't happen:
184200
*

tests/Platforms/AbstractPlatformTestCase.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\DBAL\Schema\Comparator;
1515
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
1616
use Doctrine\DBAL\Schema\Index;
17+
use Doctrine\DBAL\Schema\SchemaDiff;
1718
use Doctrine\DBAL\Schema\Table;
1819
use Doctrine\DBAL\Schema\TableDiff;
1920
use Doctrine\DBAL\Schema\UniqueConstraint;
@@ -1390,6 +1391,14 @@ public function testEmptyTableDiff(): void
13901391
self::assertSame([], $this->platform->getAlterTableSQL($diff));
13911392
}
13921393

1394+
public function testEmptySchemaDiff(): void
1395+
{
1396+
$diff = new SchemaDiff();
1397+
1398+
self::assertTrue($diff->isEmpty());
1399+
self::assertSame([], $this->platform->getAlterSchemaSQL($diff));
1400+
}
1401+
13931402
public function tearDown(): void
13941403
{
13951404
if (! isset($this->backedUpType)) {

0 commit comments

Comments
 (0)