Skip to content

Commit

Permalink
Merge branch '4.3.x' into 5.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Jan 22, 2025
2 parents ec55d06 + 5eeeb33 commit c7877f3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 30 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ all drivers and middleware.

# Upgrade to 4.3

## Deprecated using `Schema` as `AbstractAsset`

Relying on the `Schema` class extending `AbstractAsset` is deprecated. Use only the methods declared immediately in
the `Schema` class itself.

## Deprecated `ForeignKeyConstraint` methods, properties and behavior

The following `ForeignKeyConstraint` methods and property have been deprecated:
Expand Down
39 changes: 35 additions & 4 deletions src/Schema/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
use Doctrine\DBAL\SQL\Builder\CreateSchemaObjectsSQLBuilder;
use Doctrine\DBAL\SQL\Builder\DropSchemaObjectsSQLBuilder;
use Doctrine\Deprecations\Deprecation;

use function array_values;
use function count;
Expand Down Expand Up @@ -56,9 +57,9 @@
* execute them. Only the queries for the currently connected database are
* executed.
*
* @extends AbstractOptionallyNamedObject<UnqualifiedName>
* @extends AbstractAsset<UnqualifiedName>
*/
class Schema extends AbstractOptionallyNamedObject
class Schema extends AbstractAsset
{
/**
* The namespaces in this schema.
Expand Down Expand Up @@ -113,6 +114,29 @@ public function __construct(
}
}

/** @deprecated */
public function getName(): string
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/6734',
'Using Schema as AbstractAsset, including %s, is deprecated.',
__METHOD__,
);

return parent::getName();
}

/**
* The object representation of the name isn't used because {@see Schema} is not an {@see AbstractAsset}.
*
* This method implements the abstract method in the parent class and will be removed once {@see Schema} stops
* extending {@see AbstractAsset}.
*/
protected function setName(?Name $name): void
{
}

protected function getNameParser(): UnqualifiedNameParser
{
return Parsers::getUnqualifiedNameParser();
Expand Down Expand Up @@ -254,8 +278,15 @@ private function getKeyFromName(string $input): string
*/
private function resolveName(OptionallyQualifiedName $name): OptionallyQualifiedName
{
if ($name->getQualifier() === null && $this->name !== null) {
return new OptionallyQualifiedName($name->getUnqualifiedName(), $this->name->getIdentifier());
if ($name->getQualifier() === null) {
$defaultNamespaceName = $this->getName();

if ($defaultNamespaceName !== '') {
return new OptionallyQualifiedName(
$name->getUnqualifiedName(),
Identifier::quoted($defaultNamespaceName),
);
}
}

return $name;
Expand Down
26 changes: 0 additions & 26 deletions tests/Schema/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

namespace Doctrine\DBAL\Tests\Schema;

use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Schema\Exception\ImproperlyQualifiedName;
use Doctrine\DBAL\Schema\Exception\InvalidName;
use Doctrine\DBAL\Schema\Name\Identifier;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaConfig;
use Doctrine\DBAL\Schema\SchemaException;
Expand Down Expand Up @@ -408,27 +405,4 @@ public function testReferencingByUnqualifiedNameAmongQualifiedNamesWithDefaultNa
self::assertFalse($schema->hasTable('s'));
self::assertFalse($schema->hasTable('public.s'));
}

public function testQualifiedName(): void
{
$schemaConfig = new SchemaConfig();
$schemaConfig->setName('warehouse.inventory');

$this->expectException(InvalidName::class);

new Schema([], [], $schemaConfig);
}

/** @throws Exception */
public function testGetObjectName(): void
{
$schemaConfig = new SchemaConfig();
$schemaConfig->setName('public');

$schema = new Schema([], [], $schemaConfig);
$name = $schema->getObjectName();

self::assertNotNull($name);
self::assertEquals(Identifier::unquoted('public'), $name->getIdentifier());
}
}

0 comments on commit c7877f3

Please sign in to comment.