Skip to content

Commit

Permalink
Remove Connection::$_schemaManager
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Mar 8, 2021
1 parent 55692ad commit 2bf08c9
Show file tree
Hide file tree
Showing 41 changed files with 70 additions and 92 deletions.
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Upgrade to 4.0

## BC BREAK: Removed `Connection::$_schemaManager` property

The `Connection` and `AbstractSchemaManager` classes used to have a reference on each other effectively making a circular reference. Use `getSchemaManager()` to instantiate a schema manager.

## BC BREAK: Removed `Connection::$_expr` property

The `Connection` and `ExpressionBuilder` classes used to have a reference on each other effectively making a circular reference. Use `getExpressionBuilder()` to instantiate an expression builder.
Expand Down
8 changes: 4 additions & 4 deletions docs/en/reference/schema-manager.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ A Schema Manager instance helps you with the abstraction of the
generation of SQL assets such as Tables, Sequences, Foreign Keys
and Indexes.

To retrieve the ``SchemaManager`` for your connection you can use
the ``getSchemaManager()`` method:
To instantiate a ``SchemaManager`` for your connection you can use
the ``createSchemaManager()`` method:

.. code-block:: php
<?php
$sm = $conn->getSchemaManager();
$schemaManager = $conn->createSchemaManager();
Now with the ``SchemaManager`` instance in ``$sm`` you can use the
Now with the ``SchemaManager`` instance in ``$schemaManager`` you can use the
available methods to learn about your database schema:

.. note::
Expand Down
26 changes: 0 additions & 26 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,6 @@ class Connection
/** @var Parser|null */
private $parser;

/**
* The schema manager.
*
* @deprecated Use {@link createSchemaManager()} instead.
*
* @var AbstractSchemaManager|null
*/
protected $_schemaManager;

/**
* The used DBAL driver.
*
Expand Down Expand Up @@ -1420,23 +1411,6 @@ public function createSchemaManager(): AbstractSchemaManager
);
}

/**
* Gets the SchemaManager that can be used to inspect or change the
* database schema through the connection.
*
* @deprecated Use {@link createSchemaManager()} instead.
*
* @throws Exception
*/
public function getSchemaManager(): AbstractSchemaManager
{
if ($this->_schemaManager === null) {
$this->_schemaManager = $this->createSchemaManager();
}

return $this->_schemaManager;
}

/**
* Marks the current transaction so that the only possible
* outcome for the transaction to be rolled back.
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/Console/Command/ReservedWordsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
true
);

$schema = $conn->getSchemaManager()->createSchema();
$schema = $conn->createSchemaManager()->createSchema();
$visitor = new ReservedKeywordsValidator($keywords);
$schema->visit($visitor);

Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/BlobTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function setUp(): void
$table->addColumn('blobcolumn', 'blob');
$table->setPrimaryKey(['id']);

$sm = $this->connection->getSchemaManager();
$sm = $this->connection->createSchemaManager();
$sm->dropAndCreateTable($table);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/DataAccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected function setUp(): void
$table->addColumn('test_datetime', 'datetime', ['notnull' => false]);
$table->setPrimaryKey(['test_int']);

$sm = $this->connection->getSchemaManager();
$sm = $this->connection->createSchemaManager();
$sm->createTable($table);

$this->connection->insert('fetch_table', [
Expand Down Expand Up @@ -742,7 +742,7 @@ public function testSqliteDateArithmeticWithDynamicInterval(): void
$table->addColumn('test_days', 'integer');
$table->setPrimaryKey(['test_date']);

$sm = $this->connection->getSchemaManager();
$sm = $this->connection->createSchemaManager();
$sm->createTable($table);

$this->connection->insert('fetch_table_date_math', ['test_date' => '2010-01-01', 'test_days' => 10]);
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Driver/OCI8/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ protected function setUp(): void
public function testLastInsertIdAcceptsFqn(): void
{
$platform = $this->connection->getDatabasePlatform();
$schemaManager = $this->connection->getSchemaManager();
$schemaManager = $this->connection->createSchemaManager();

$table = new Table('DBAL2595');
$table->addColumn('id', 'integer', ['autoincrement' => true]);
Expand Down
6 changes: 3 additions & 3 deletions tests/Functional/ExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testPrimaryConstraintViolationException(): void
$table->addColumn('id', 'integer', []);
$table->setPrimaryKey(['id']);

$this->connection->getSchemaManager()->createTable($table);
$this->connection->createSchemaManager()->createTable($table);

$this->connection->insert('duplicatekey_table', ['id' => 1]);

Expand All @@ -76,7 +76,7 @@ public function testTableNotFoundException(): void

public function testTableExistsException(): void
{
$schemaManager = $this->connection->getSchemaManager();
$schemaManager = $this->connection->createSchemaManager();
$table = new Table('alreadyexist_table');
$table->addColumn('id', 'integer', []);
$table->setPrimaryKey(['id']);
Expand Down Expand Up @@ -160,7 +160,7 @@ public function testSyntaxErrorException(): void
$table->addColumn('id', 'integer', []);
$table->setPrimaryKey(['id']);

$this->connection->getSchemaManager()->createTable($table);
$this->connection->createSchemaManager()->createTable($table);

$sql = 'SELECT id FRO syntax_error_table';
$this->expectException(Exception\SyntaxErrorException::class);
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/ForeignKeyExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function setUp(): void
self::markTestSkipped('Driver does not support special exception handling.');
}

$schemaManager = $this->connection->getSchemaManager();
$schemaManager = $this->connection->createSchemaManager();

$table = new Table('constraint_error_table');
$table->addColumn('id', 'integer', []);
Expand All @@ -43,7 +43,7 @@ protected function tearDown(): void
{
parent::tearDown();

$schemaManager = $this->connection->getSchemaManager();
$schemaManager = $this->connection->createSchemaManager();

$schemaManager->dropTable('owning_table');
$schemaManager->dropTable('constraint_error_table');
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/LegacyAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function setUp(): void
$table->addColumn('test_string', 'string', ['length' => 3]);
$table->setPrimaryKey(['test_int']);

$sm = $this->connection->getSchemaManager();
$sm = $this->connection->createSchemaManager();
$sm->dropAndCreateTable($table);

$this->connection->insert('legacy_table', [
Expand Down
6 changes: 3 additions & 3 deletions tests/Functional/LockMode/NoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public function setUp(): void
$table->addColumn('id', 'integer');
$table->setPrimaryKey(['id']);

$this->connection->getSchemaManager()->dropAndCreateTable($table);
$this->connection->createSchemaManager()->dropAndCreateTable($table);

$this->connection2 = TestUtil::getConnection();

if ($this->connection2->getSchemaManager()->tableExists('users')) {
if ($this->connection2->createSchemaManager()->tableExists('users')) {
return;
}

Expand All @@ -69,7 +69,7 @@ public function tearDown(): void

$this->connection2->close();

$this->connection->getSchemaManager()->dropTable('users');
$this->connection->createSchemaManager()->dropTable('users');

if (! $this->connection->getDatabasePlatform() instanceof SQLServer2012Platform) {
return;
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/ModifyLimitQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function setUp(): void
$table2->addColumn('test_int', 'integer');
$table2->setPrimaryKey(['id']);

$sm = $this->connection->getSchemaManager();
$sm = $this->connection->createSchemaManager();
$sm->createTable($table);
$sm->createTable($table2);
self::$tableCreated = true;
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/NamedParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ protected function setUp(): void
{
parent::setUp();

if ($this->connection->getSchemaManager()->tableExists('ddc1372_foobar')) {
if ($this->connection->createSchemaManager()->tableExists('ddc1372_foobar')) {
return;
}

Expand All @@ -165,7 +165,7 @@ protected function setUp(): void
$table->addColumn('bar', 'string', ['length' => 1]);
$table->setPrimaryKey(['id']);

$sm = $this->connection->getSchemaManager();
$sm = $this->connection->createSchemaManager();
$sm->createTable($table);

$this->connection->insert('ddc1372_foobar', [
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Platform/AddColumnWithDefaultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AddColumnWithDefaultTest extends FunctionalTestCase
{
public function testAddColumnWithDefault(): void
{
$schemaManager = $this->connection->getSchemaManager();
$schemaManager = $this->connection->createSchemaManager();

$table = new Table('add_default_test');

Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Platform/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected function assertColumn(string $type, array $column, string $value, int
$table = new Table('column_test');
$table->addColumn('val', $type, $column);

$sm = $this->connection->getSchemaManager();
$sm = $this->connection->createSchemaManager();
$sm->dropAndCreateTable($table);

self::assertSame(1, $this->connection->insert('column_test', ['val' => $value], [$bindType]));
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Platform/DateExpressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function testDifference(string $date1, string $date2, int $expected): voi
$table = new Table('date_expr_test');
$table->addColumn('date1', 'datetime');
$table->addColumn('date2', 'datetime');
$this->connection->getSchemaManager()->dropAndCreateTable($table);
$this->connection->createSchemaManager()->dropAndCreateTable($table);
$this->connection->insert('date_expr_test', [
'date1' => $date1,
'date2' => $date2,
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Platform/DefaultExpressionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private function assertDefaultExpression(string $type, callable $expression): vo
$table = new Table('default_expr_test');
$table->addColumn('actual_value', $type);
$table->addColumn('default_value', $type, ['default' => $defaultSql]);
$this->connection->getSchemaManager()->dropAndCreateTable($table);
$this->connection->createSchemaManager()->dropAndCreateTable($table);

$this->connection->executeStatement(
sprintf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function setUp(): void
*/
public function testAlterPrimaryKeyToAutoIncrementColumn(): void
{
$schemaManager = $this->connection->getSchemaManager();
$schemaManager = $this->connection->createSchemaManager();
$schema = $schemaManager->createSchema();

$table = $schema->createTable('dbal2807');
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Platform/PlatformRestrictionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public function testMaxIdentifierLengthLimitWithAutoIncrement(): void
$table = new Table($tableName);
$table->addColumn($columnName, 'integer', ['autoincrement' => true]);
$table->setPrimaryKey([$columnName]);
$this->connection->getSchemaManager()->dropAndCreateTable($table);
$createdTable = $this->connection->getSchemaManager()->listTableDetails($tableName);
$this->connection->createSchemaManager()->dropAndCreateTable($table);
$createdTable = $this->connection->createSchemaManager()->listTableDetails($tableName);

self::assertTrue($createdTable->hasColumn($columnName));
self::assertTrue($createdTable->hasPrimaryKey());
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/PortabilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function setUp(): void
$table->setPrimaryKey(['Test_Int']);

try {
$sm = $this->connection->getSchemaManager();
$sm = $this->connection->createSchemaManager();
$sm->createTable($table);

$this->connection->insert('portability_table', [
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/PrimaryReadReplicaConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ protected function setUp(): void
$table->addColumn('test_int', 'integer');
$table->setPrimaryKey(['test_int']);

$sm = $this->connection->getSchemaManager();
$sm = $this->connection->createSchemaManager();
$sm->createTable($table);
} catch (Throwable $e) {
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/ResultCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function setUp(): void
]);
$table->setPrimaryKey(['test_int']);

$sm = $this->connection->getSchemaManager();
$sm = $this->connection->createSchemaManager();
$sm->dropAndCreateTable($table);

foreach ($this->expectedResult as $row) {
Expand Down
8 changes: 4 additions & 4 deletions tests/Functional/Schema/ColumnCommentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function setUp(): void
$table->addColumn($name, $type, $options);
}

$this->connection->getSchemaManager()
$this->connection->createSchemaManager()
->dropAndCreateTable($table);
}

Expand Down Expand Up @@ -92,7 +92,7 @@ public function testAlterColumnComment(string $comment1, string $comment2): void
$table1 = new Table('column_comments');
$table1->addColumn('id', 'integer', ['comment' => $comment1]);

$this->connection->getSchemaManager()
$this->connection->createSchemaManager()
->dropAndCreateTable($table1);

$table2 = clone $table1;
Expand All @@ -101,7 +101,7 @@ public function testAlterColumnComment(string $comment1, string $comment2): void
$diff = (new Comparator())->diffTable($table1, $table2);
self::assertNotNull($diff);

$sm = $this->connection->getSchemaManager();
$sm = $this->connection->createSchemaManager();
$sm->alterTable($diff);

$this->assertColumnComment('column_comments', 'id', $comment2);
Expand All @@ -125,7 +125,7 @@ private function assertColumnComment(string $table, string $column, string $expe
{
self::assertSame(
$expectedComment,
$this->connection->getSchemaManager()
$this->connection->createSchemaManager()
->listTableDetails($table)
->getColumn($column)
->getComment()
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Schema/ComparatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected function setUp(): void
{
parent::setUp();

$this->schemaManager = $this->connection->getSchemaManager();
$this->schemaManager = $this->connection->createSchemaManager();
$this->comparator = new Comparator();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Schema/DefaultValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected function setUp(): void
]);
}

$this->connection->getSchemaManager()
$this->connection->createSchemaManager()
->dropAndCreateTable($table);

$this->connection->insert('default_value', ['id' => 1]);
Expand All @@ -49,7 +49,7 @@ public function testEscapedDefaultValueCanBeIntrospected(string $name, ?string $
self::assertSame(
$expectedDefault,
$this->connection
->getSchemaManager()
->createSchemaManager()
->listTableDetails('default_value')
->getColumn($name)
->getDefault()
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/Schema/MySQLSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ public function testListTableColumnsThrowsDatabaseRequired(): void
unset($params['dbname']);

$connection = DriverManager::getConnection($params);
$schemaManager = $connection->getSchemaManager();
$schemaManager = $connection->createSchemaManager();

$this->expectException(DatabaseRequired::class);
$this->expectExceptionMessage(
Expand Down
4 changes: 2 additions & 2 deletions tests/Functional/Schema/OracleSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function testAlterTableColumnNotNull(): void
public function testListDatabases(): void
{
// We need a privileged connection to create the database.
$sm = TestUtil::getPrivilegedConnection()->getSchemaManager();
$sm = TestUtil::getPrivilegedConnection()->createSchemaManager();

$sm->dropAndCreateDatabase('c##test_create_database');

Expand Down Expand Up @@ -248,7 +248,7 @@ public function testListTableColumnsSameTableNamesInDifferentSchemas(): void

$otherTable = new Table($table->getName());
$otherTable->addColumn('id', Types::STRING, ['length' => 32]);
TestUtil::getPrivilegedConnection()->getSchemaManager()->dropAndCreateTable($otherTable);
TestUtil::getPrivilegedConnection()->createSchemaManager()->dropAndCreateTable($otherTable);

$columns = $this->schemaManager->listTableColumns($table->getName(), $this->connection->getDatabase());
self::assertCount(7, $columns);
Expand Down

0 comments on commit 2bf08c9

Please sign in to comment.