diff --git a/lib/Migration/RepairSteps/CreateUniqueIndices.php b/lib/Migration/RepairSteps/CreateUniqueIndices.php index af66131e2..72708adc6 100644 --- a/lib/Migration/RepairSteps/CreateUniqueIndices.php +++ b/lib/Migration/RepairSteps/CreateUniqueIndices.php @@ -43,8 +43,13 @@ public function run(IOutput $output): void { // But the app relies on these indices to function properly, so we have to ensure they are created. // If for any reasons the unique indices cannot be created, we remove all unique indices and create them again. // This is a workaround for index conflicts that might occur during migration. + $output->warning('Polls - Exception during index migration: ' . $e->getMessage() . "\n" . $e->getTraceAsString()); + if (str_contains($e->getMessage(), 'already exists') || str_contains($e->getMessage(), '42P07')) { - $output->warning('Polls - Index conflict detected, rebuilding unique indices: ' . $e->getMessage()); + $output->warning('Polls - Index conflict detected, rebuilding unique indices.'); + if ($this->connection->inTransaction()) { + $this->connection->rollBack(); + } $this->schema = $this->connection->createSchema(); $this->indexManager->setSchema($this->schema); $messages = array_merge($messages, $this->indexManager->repairPrimaryKeys());