Skip to content

Commit

Permalink
use empty unique index name if array key is numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
deasraze committed Feb 29, 2024
1 parent 71d7ec2 commit a97c431
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/Tools/SchemaTool.php
Expand Up @@ -337,8 +337,14 @@ public function getSchemaFromMetadata(array $classes): Schema

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

foreach ($table->getIndexes() as $tableIndexName => $tableIndex) {
if ($tableIndex->isFulfilledBy($uniqIndex)) {
Expand All @@ -347,7 +353,11 @@ public function getSchemaFromMetadata(array $classes): Schema
}
}

$table->addUniqueIndex($uniqIndex->getColumns(), $uniqIndexName, $indexData['options'] ?? []);
$table->addUniqueIndex(
$uniqIndex->getColumns(),
$uniqIndex->getName() === '' ? null : $uniqIndex->getName(),
$indexData['options'] ?? [],
);
}
}

Expand Down

0 comments on commit a97c431

Please sign in to comment.