8000 Deprecate mixing qualified and unqualified names by morozov · Pull Request #6677 · doctrine/dbal · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Deprecate mixing qualified and unqualified names #6677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 29, 2024

Conversation

morozov
Copy link
Member
@morozov morozov commented Dec 28, 2024
Q A
Type improvement/deprecation

Technically, each of the three commits could be contributed as a separate pull request but I'll publish them altogether in the interest of time as each of them depends on the previous one.

1. Population of the current SQL Server schema

Technically, the fact that the current SQL Server schema isn't populated during introspection is a bug. Once introspected, a PostgreSQL schema allows referencing its objects by unqualified or qualified name but the SQL Server schema doesn't. This commit addresses this issue and reworks an existing test to cover this scenario.

2. Deprecation of mixing qualified and unqualified names in a schema

Currently, a schema allows registering objects with a mixture of unqualified names (e.g. customers) and qualified names (e.g. public.customers). It compares names as strings, so in the absence of a default schema name, "customers" ≠ "public.customers", however, it's a logical error because these two values are incomparable (again, similar to "5" and "5 meters").

In order to make the schema API more robust, mixing incomparable types of names is deprecated.

Using unqualified names

Unqualified names can be used to add objects to or reference objects in a schema only if doesn't contain objects with qualified names or has a default namespace configuration.

Using qualified names

Qualified names can be used to add objects to or reference objects in a schema only if doesn't contain objects with unqualified names.

Considered alternatives

Whether a given schema uses unqualified or qualified names is determined at runtime. An even more robust approach would be parameterize the schema class with the type of its objects' names and use this information for static analysis. However, the type of the names is defined by the target database platform, which is determined at runtime based on connection parameters, so the static typing is not feasible.

3. Deprecation of AbstractAsset::isIdentifierQuoted()

Once these changes are merged into 5.0.x, it will be possible to stop using AbstractAsset::isIdentifierQuoted(). At that point, we should be able to remove it.

The problem with this method is that it accepts a name that potentially consists of multiple identifiers and returns the value based on whether the first one is quoted. This is incorrect as each identifier may or may not be quoted individually.

@@ -228,7 +228,10 @@ public function testHasTableForQuotedAsset(): void

public function testHasNamespace(): void
{
$schema = new Schema();
$schemaConfig = new SchemaConfig();
$schemaConfig->setName('public');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and other similarly modified tests operate unqualified and qualified names. From now on, this is only allowed if the schema has a default namespace configuration.

@morozov morozov added this to the 4.3.0 milestone Dec 29, 2024
@morozov morozov marked this pull request as ready for review December 29, 2024 02:28
@morozov morozov requested a review from greg0ire December 29, 2024 02:28
* Indicates whether the schema uses unqualified names for its objects. Once this flag is set to true, it won't be
* unset even after the objects with unqualified names have been dropped from the schema.
*/
private bool $usesUnqualifiedNames = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this flag write once? Should it be marked as such by using @readonly?

Copy link
Member Author
@morozov morozov Dec 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not exactly write once, it can be flipped once from false to true. @readonly might be confusing, if the reader assumes the same contract as the one provided by the readonly modifier:

[...] which prevents modification of the property after initialization.

This flag is initialized as f 8000 alse and can be modified at any point in time to true or never modified.

@morozov morozov merged commit 69d5e34 into doctrine:4.3.x Dec 29, 2024
67 checks passed
@morozov morozov deleted the deprecate-mixing-schema-name-types branch December 29, 2024 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0