From 4e53f63a8f1b9968d74fb6de6c8a12d3030ffe3d Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 19 Aug 2020 23:13:04 -0700 Subject: [PATCH] Remove the Synchronizer package --- UPGRADE.md | 4 + .../AbstractSchemaSynchronizer.php | 52 ------ .../Synchronizer/SchemaSynchronizer.php | 74 -------- .../SingleDatabaseSynchronizer.php | 160 ------------------ .../SingleDatabaseSynchronizerTest.php | 78 --------- 5 files changed, 4 insertions(+), 364 deletions(-) delete mode 100644 src/Schema/Synchronizer/AbstractSchemaSynchronizer.php delete mode 100644 src/Schema/Synchronizer/SchemaSynchronizer.php delete mode 100644 src/Schema/Synchronizer/SingleDatabaseSynchronizer.php delete mode 100644 tests/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php diff --git a/UPGRADE.md b/UPGRADE.md index db0ca34d5cd..1d847343eae 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 3.0 +## BC BREAK: removed `Synchronizer` package + +The `Doctrine\DBAL\Schema\Synchronizer\SchemaSynchronizer` interface and all its implementations have been removed. + ## BC BREAK: removed wrapper `Connection` methods The following methods of the `Connection` class have been removed: diff --git a/src/Schema/Synchronizer/AbstractSchemaSynchronizer.php b/src/Schema/Synchronizer/AbstractSchemaSynchronizer.php deleted file mode 100644 index 93d34e14c86..00000000000 --- a/src/Schema/Synchronizer/AbstractSchemaSynchronizer.php +++ /dev/null @@ -1,52 +0,0 @@ -conn = $conn; - } - - /** - * @param string[] $sql - * - * @return void - */ - protected function processSqlSafely(array $sql) - { - foreach ($sql as $s) { - try { - $this->conn->executeStatement($s); - } catch (Throwable $e) { - } - } - } - - /** - * @param string[] $sql - * - * @return void - * - * @throws DBALException - */ - protected function processSql(array $sql) - { - foreach ($sql as $s) { - $this->conn->executeStatement($s); - } - } -} diff --git a/src/Schema/Synchronizer/SchemaSynchronizer.php b/src/Schema/Synchronizer/SchemaSynchronizer.php deleted file mode 100644 index a10d3b7f327..00000000000 --- a/src/Schema/Synchronizer/SchemaSynchronizer.php +++ /dev/null @@ -1,74 +0,0 @@ -platform = $conn->getDatabasePlatform(); - } - - /** - * {@inheritdoc} - */ - public function getCreateSchema(Schema $createSchema) - { - return $createSchema->toSql($this->platform); - } - - /** - * {@inheritdoc} - */ - public function getUpdateSchema(Schema $toSchema, $noDrops = false) - { - $comparator = new Comparator(); - $sm = $this->conn->getSchemaManager(); - - $fromSchema = $sm->createSchema(); - $schemaDiff = $comparator->compare($fromSchema, $toSchema); - - if ($noDrops) { - return $schemaDiff->toSaveSql($this->platform); - } - - return $schemaDiff->toSql($this->platform); - } - - /** - * {@inheritdoc} - */ - public function getDropSchema(Schema $dropSchema) - { - $visitor = new DropSchemaSqlCollector($this->platform); - $sm = $this->conn->getSchemaManager(); - - $fullSchema = $sm->createSchema(); - - foreach ($fullSchema->getTables() as $table) { - if ($dropSchema->hasTable($table->getName())) { - $visitor->acceptTable($table); - } - - foreach ($table->getForeignKeys() as $foreignKey) { - if (! $dropSchema->hasTable($table->getName())) { - continue; - } - - if (! $dropSchema->hasTable($foreignKey->getForeignTableName())) { - continue; - } - - $visitor->acceptForeignKey($table, $foreignKey); - } - } - - if (! $this->platform->supportsSequences()) { - return $visitor->getQueries(); - } - - foreach ($dropSchema->getSequences() as $sequence) { - $visitor->acceptSequence($sequence); - } - - foreach ($dropSchema->getTables() as $table) { - $primaryKey = $table->getPrimaryKey(); - - if ($primaryKey === null) { - continue; - } - - $columns = $primaryKey->getColumns(); - - if (count($columns) > 1) { - continue; - } - - $checkSequence = $table->getName() . '_' . $columns[0] . '_seq'; - if (! $fullSchema->hasSequence($checkSequence)) { - continue; - } - - $visitor->acceptSequence($fullSchema->getSequence($checkSequence)); - } - - return $visitor->getQueries(); - } - - /** - * {@inheritdoc} - */ - public function getDropAllSchema() - { - $sm = $this->conn->getSchemaManager(); - $visitor = new DropSchemaSqlCollector($this->platform); - - $schema = $sm->createSchema(); - $schema->visit($visitor); - - return $visitor->getQueries(); - } - - /** - * {@inheritdoc} - */ - public function createSchema(Schema $createSchema) - { - $this->processSql($this->getCreateSchema($createSchema)); - } - - /** - * {@inheritdoc} - */ - public function updateSchema(Schema $toSchema, $noDrops = false) - { - $this->processSql($this->getUpdateSchema($toSchema, $noDrops)); - } - - /** - * {@inheritdoc} - */ - public function dropSchema(Schema $dropSchema) - { - $this->processSqlSafely($this->getDropSchema($dropSchema)); - } - - /** - * {@inheritdoc} - */ - public function dropAllSchema() - { - $this->processSql($this->getDropAllSchema()); - } -} diff --git a/tests/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php b/tests/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php deleted file mode 100644 index 4354620086e..00000000000 --- a/tests/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php +++ /dev/null @@ -1,78 +0,0 @@ -conn = DriverManager::getConnection([ - 'driver' => 'pdo_sqlite', - 'memory' => true, - ]); - $this->synchronizer = new SingleDatabaseSynchronizer($this->conn); - } - - public function testGetCreateSchema(): void - { - $schema = new Schema(); - $table = $schema->createTable('test'); - $table->addColumn('id', 'integer'); - $table->setPrimaryKey(['id']); - - $sql = $this->synchronizer->getCreateSchema($schema); - self::assertEquals(['CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))'], $sql); - } - - public function testGetUpdateSchema(): void - { - $schema = new Schema(); - $table = $schema->createTable('test'); - $table->addColumn('id', 'integer'); - $table->setPrimaryKey(['id']); - - $sql = $this->synchronizer->getUpdateSchema($schema); - self::assertEquals(['CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(id))'], $sql); - } - - public function testGetDropSchema(): void - { - $schema = new Schema(); - $table = $schema->createTable('test'); - $table->addColumn('id', 'integer'); - $table->setPrimaryKey(['id']); - - $this->synchronizer->createSchema($schema); - - $sql = $this->synchronizer->getDropSchema($schema); - self::assertEquals(['DROP TABLE test'], $sql); - } - - public function testGetDropAllSchema(): void - { - $schema = new Schema(); - $table = $schema->createTable('test'); - $table->addColumn('id', 'integer'); - $table->setPrimaryKey(['id']); - - $this->synchronizer->createSchema($schema); - - $sql = $this->synchronizer->getDropAllSchema(); - self::assertEquals(['DROP TABLE test'], $sql); - } -}