Remove the Synchronizer package

parent 79c34f77
# Upgrade to 3.0 # 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 ## BC BREAK: removed wrapper `Connection` methods
The following methods of the `Connection` class have been removed: The following methods of the `Connection` class have been removed:
......
<?php
namespace Doctrine\DBAL\Schema\Synchronizer;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Throwable;
/**
* Abstract schema synchronizer with methods for executing batches of SQL.
*
* @deprecated
*/
abstract class AbstractSchemaSynchronizer implements SchemaSynchronizer
{
/** @var Connection */
protected $conn;
public function __construct(Connection $conn)
{
$this->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);
}
}
}
<?php
namespace Doctrine\DBAL\Schema\Synchronizer;
use Doctrine\DBAL\Schema\Schema;
/**
* The synchronizer knows how to synchronize a schema with the configured
* database.
*
* @deprecated
*/
interface SchemaSynchronizer
{
/**
* Gets the SQL statements that can be executed to create the schema.
*
* @return string[]
*/
public function getCreateSchema(Schema $createSchema);
/**
* Gets the SQL Statements to update given schema with the underlying db.
*
* @param bool $noDrops
*
* @return string[]
*/
public function getUpdateSchema(Schema $toSchema, $noDrops = false);
/**
* Gets the SQL Statements to drop the given schema from underlying db.
*
* @return string[]
*/
public function getDropSchema(Schema $dropSchema);
/**
* Gets the SQL statements to drop all schema assets from underlying db.
*
* @return string[]
*/
public function getDropAllSchema();
/**
* Creates the Schema.
*
* @return void
*/
public function createSchema(Schema $createSchema);
/**
* Updates the Schema to new schema version.
*
* @param bool $noDrops
*
* @return void
*/
public function updateSchema(Schema $toSchema, $noDrops = false);
/**
* Drops the given database schema from the underlying db.
*
* @return void
*/
public function dropSchema(Schema $dropSchema);
/**
* Drops all assets from the underlying db.
*
* @return void
*/
public function dropAllSchema();
}
<?php
namespace Doctrine\DBAL\Schema\Synchronizer;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Visitor\DropSchemaSqlCollector;
use function count;
/**
* Schema Synchronizer for Default DBAL Connection.
*
* @deprecated
*/
class SingleDatabaseSynchronizer extends AbstractSchemaSynchronizer
{
/** @var AbstractPlatform */
private $platform;
public function __construct(Connection $conn)
{
parent::__construct($conn);
$this->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());
}
}
<?php
namespace Doctrine\DBAL\Tests\Schema\Synchronizer;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Synchronizer\SingleDatabaseSynchronizer;
use PHPUnit\Framework\TestCase;
/**
* @requires extension pdo_sqlite
*/
class SingleDatabaseSynchronizerTest extends TestCase
{
/** @var Connection */
private $conn;
/** @var SingleDatabaseSynchronizer */
private $synchronizer;
protected function setUp(): void
{
$this->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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment