Skip to content

Fix creation of unnamed unique constraints #6668

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 25, 2024

Conversation

morozov
Copy link
Member

@morozov morozov commented Dec 25, 2024

Q A
Type bug

Note that even though the $name parameter in the UniqueConstraint constructor isn't nullable, the original implementation attempted to handle constraints with empty name:

$constraintName = $name->getQuotedName($this);
$constraintName = ! empty($constraintName) ? $constraintName . ' ' : '';

Also, constraint names in SQL are optional for all supported platforms. Therefore, I consider the behavior of improper handling of unnamed constraints a bug.

Two issues are being fixed:

  1. If the unique constraint name is omitted (empty), the DBAL will generate invalid DDL (both in the case of CREATE TABLE and ALTER TABLE).
  2. If there are more than one unique constraint with omitted name, their definitions will clash and only one will be created.

Both of these edge cases are correctly handled for foreign key constraints, which can be referenced as the proper implementation.

First, these keys are not used in the code. Second, they cause clashing
between multiple unnamed unique constraints.
@morozov morozov changed the title Fix creation of unique constraints with system-generated name Fix creation of unnamed unique constraints Dec 25, 2024
@morozov morozov marked this pull request as ready for review December 25, 2024 18:07
@morozov morozov requested a review from greg0ire December 25, 2024 18:07
Copy link
Member

@greg0ire greg0ire left a comment

Choose a reason for hiding this comment

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

Didn't know about this syntax :)

@morozov morozov merged commit 6428f1a into doctrine:4.2.x Dec 25, 2024
67 checks passed
@morozov morozov added this to the 4.2.2 milestone Dec 25, 2024
@morozov morozov deleted the unnamed-unique-constraints branch March 7, 2025 18:31
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