Skip to content

Commit 20cb10b

Browse files
committed
updateTable prevent index name conflict #1235
1 parent 92dfe2f commit 20cb10b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

packages/database/src/Manager/TableManager.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ public function update(Schema|callable $schema): static
9090
$this->dropIndex($index->indexName);
9191
}
9292

93+
if ($this->hasConstraint($index->indexName)) {
94+
$this->dropConstraint($index->indexName);
95+
}
96+
9397
$this->addIndex($index);
9498
}
9599

@@ -98,6 +102,10 @@ public function update(Schema|callable $schema): static
98102
$this->dropConstraint($constraint->constraintName);
99103
}
100104

105+
if ($this->hasIndex($constraint->constraintName)) {
106+
$this->dropIndex($constraint->constraintName);
107+
}
108+
101109
$this->addConstraint($constraint);
102110
}
103111

@@ -428,7 +436,7 @@ public function dropIndex(array|string $names): static
428436
$platform = $this->getPlatform();
429437

430438
foreach ((array) $names as $name) {
431-
if (!$this->hasIndex($name)) {
439+
if ($this->hasIndex($name)) {
432440
$platform->dropIndex($this->getName(), $name, $this->schemaName);
433441
}
434442
}

0 commit comments

Comments
 (0)