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

Use the same unique index name #11273

Closed
wants to merge 2 commits into from

Conversation

deasraze
Copy link

Fixes #11246.

@@ -337,7 +337,8 @@ public function getSchemaFromMetadata(array $classes): Schema

if (isset($class->table['uniqueConstraints'])) {
foreach ($class->table['uniqueConstraints'] as $indexName => $indexData) {
$uniqIndex = new Index($indexName, $this->getIndexColumns($class, $indexData), true, false, [], $indexData['options'] ?? []);
$uniqIndexName = is_numeric($indexName) ? null : $indexName;
$uniqIndex = new Index($uniqIndexName, $this->getIndexColumns($class, $indexData), true, false, [], $indexData['options'] ?? []);
Copy link
Member

Choose a reason for hiding this comment

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

ORM 3.0 still supports DBAL 3.6 and up, where Doctrine\DBAL\Schema\Index can't have null as an index name. A nullable name was introduced in DBAL 4.0. It looks like the Index instance is only created to be used in $tableIndex->isFulfilledBy($uniqIndex) a few lines later.

Copy link
Author

@deasraze deasraze Feb 20, 2024

Choose a reason for hiding this comment

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

Hmm, yes, you are right. As I understand it, this check was added as part of issue #1375. Under the current circumstances, there is another quick fix that I see: to compare with existing indexes, use an index with an empty name if the array key is a number. Given that the index name is not used for comparison and is declared as an empty string by default, this looks like it would work. Tests also confirm this for dbal versions 3.8 and 4.0. However, when adding a unique index, passing the index name as null seems to be fine, as long as the index name is empty. On the other hand, it doesn't seem very nice. What do you think about that ?

Copy link
Member

Choose a reason for hiding this comment

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

I don't expect that the name will be used in a check, because the focus is on involved columns to prevent duplicates. It would be the same having two unique indices with null. Please try your suggested approach on this.

Copy link
Author

Choose a reason for hiding this comment

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

Fine, I've made a few minor edits.

@SenseException
Copy link
Member

Thank you. This would at least handle the type error. Could you please do a rebase of your branch an resolve the conflicts?

derrabus
derrabus previously approved these changes Mar 13, 2024
@derrabus derrabus added the Bug label Mar 13, 2024
@derrabus derrabus added this to the 3.1.1 milestone Mar 13, 2024
@derrabus derrabus changed the base branch from 3.0.x to 3.1.x March 13, 2024 06:51
@derrabus derrabus dismissed their stale review March 13, 2024 06:51

The base branch was changed.

@derrabus
Copy link
Member

Actually, this should've been fixed by #11314 already which was shipped with 2.18.3 and 3.0.3. Can you please check if you still have this issue with the latest ORM release (3.1.0 or 2.19.0 at the moment)?

@deasraze
Copy link
Author

I checked on the latest release 3.1.0 with tests from the current PR. The issue is not reproducible. In that case, I'm closing the PR.

@deasraze deasraze closed this Mar 13, 2024
@derrabus
Copy link
Member

Thank you!

@derrabus derrabus removed this from the 3.1.1 milestone Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UniqueIndex attribute on entity can cause some packaged CLI tools to error
3 participants