Skip to content
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

Auto-quote introspected PostgreSQL identifiers #6756

Merged
merged 1 commit into from
Feb 2, 2025

Conversation

morozov
Copy link
Member

@morozov morozov commented Feb 2, 2025

Schema managers for the platforms that respect SQL-92 with regard to identifier case sensitivity should introspect the identifiers with characters in lower case (or, for PostgreSQL, in upper case) as quoted. Otherwise, their actual case may get lost in translation.

Note

All identifiers should be always introspected as quoted but prior to #6589 (DBAL 5.0) it would be a BC break.

Currently, the Oracle schema manager does it via getQuotedIdentifierName(). The PostgreSQL one uses quote_ident() in schema introspection queries, but inconsistently, which leads to the bugs:

  1. If an index column has upper-case letters, the column name isn't quoted. The first bug is covered by the reworked test.
  2. If there are upper- and lower-case tables in the same schema (e.g. Users and users), all columns, indexes and foreign keys will be attributed to the lower-case one. This is covered by testDropWithAutoincrement(). If an upper-case table is introspected as unquoted, it will try to drop it without quoting the name and fail (because the database will automatically lower-case the unquoted name).

}

if (! $platform instanceof OraclePlatform && ! $platform instanceof PostgreSQLPlatform) {
self::markTestSkipped('The current platform does not auto-quote introspected identifiers.');
Copy link
Member Author

@morozov morozov Feb 2, 2025

Choose a reason for hiding this comment

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

This isn't a problem per se. Whether the given schema manager will quote certain identifiers or not, we want to make sure that they are introspected in the proper case. Unfortunately, there's no public API to get the original case of an index or constraint column. For example:

  1. Index::getColumns() returns lower-cased column names.
  2. Index::getQuotedColumns() quotes the column names only if they are explicitly marked as quoted (e.g. by the Oracle or now PostgreSQL schema manager during introspection).

In DBAL 4.3, this issue no longer exists for foreign key constraints (#6728) but still exists for indexes. We will be able to run this test consistently on all platforms on DBAL 5.0.

@morozov morozov marked this pull request as ready for review February 2, 2025 03:04
@morozov morozov added the Tables label Feb 2, 2025
@morozov morozov requested a review from greg0ire February 2, 2025 03:05
@morozov morozov merged commit da19422 into doctrine:3.9.x Feb 2, 2025
68 checks passed
@morozov morozov deleted the auto-quote-postgres-identifiers branch February 2, 2025 15:40
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