Skip to content

Rework foreign key constraint introspection on PostgreSQL#6727

Merged
morozov merged 1 commit intodoctrine:5.0.xfrom
morozov:postgres-foreign-key-introspection
Jan 17, 2025
Merged

Rework foreign key constraint introspection on PostgreSQL#6727
morozov merged 1 commit intodoctrine:5.0.xfrom
morozov:postgres-foreign-key-introspection

Conversation

@morozov
Copy link
Member

@morozov morozov commented Jan 17, 2025

The problem with the existing implementation is that it parses the constraint DDL, so the referenced table name is represented as a SQL expression that needs to be parsed (e.g. inventory."products").

As we're switching to object names represented as value objects, I want to avoid the need to parse this SQL and instead initialize an OptionallyQualifiedName from two distinct values (the schema name and table name). This is already the case for all other platforms.

Additionally, the original implementation likely has these bugs:

  1. It won't correctly parse referencing or referencing column names containing comma.
  2. Prior to 4.3 (Deprecate relying on the current implementation of the database object name parser #6592), if the referenced table schema needs to be quoted (e.g. because it has upper-case letters), the DBAL will fail to parse the quoted qualified name (e.g. "Inventory".products).

Subsequently, this unification will allow to remove some boilerplate schema introspection code.

The new implementation is borrowed from PostgreSQL JDBC Driver.

Note that this rework isn't being ported to 4.3.x because this implementation loses the information about whether or not a given name used in the constraint (e.g. column names or the referenced table name) need to be quoted. If there was an integration test that covered a foreign key constraint with columns in the upper case, it would have failed. In a subsequent PR, I will make all introspected names quoted as they are introspected in their natural case, which should be preserved.

@morozov morozov force-pushed the postgres-foreign-key-introspection branch from a74ca97 to f1068e6 Compare January 17, 2025 08:14
@morozov morozov merged commit 7ebe4c9 into doctrine:5.0.x Jan 17, 2025
@morozov morozov deleted the postgres-foreign-key-introspection branch January 17, 2025 16:06
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants