Skip to content

Commit

Permalink
do not break upgrade if index names are not unique
Browse files Browse the repository at this point in the history
Signed-off-by: Simon L <[email protected]>
  • Loading branch information
szaimen committed Feb 5, 2024
1 parent a026048 commit 1e4cf27
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/private/DB/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,9 @@ public function ensureOracleConstraints(Schema $sourceSchema, Schema $targetSche
public function ensureUniqueNamesConstraints(Schema $targetSchema): void {
$constraintNames = [];

/** @var LoggerInterface $logger */
$logger = \OC::$server->get(LoggerInterface::class);

$sequences = $targetSchema->getSequences();

foreach ($targetSchema->getTables() as $table) {
Expand All @@ -668,14 +671,14 @@ public function ensureUniqueNamesConstraints(Schema $targetSchema): void {
}

if (isset($constraintNames[$thing->getName()])) {
throw new \InvalidArgumentException('Index name "' . $thing->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".');
$logger->error('Index name "' . $thing->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".');
}
$constraintNames[$thing->getName()] = $table->getName();
}

foreach ($table->getForeignKeys() as $thing) {
if (isset($constraintNames[$thing->getName()])) {
throw new \InvalidArgumentException('Foreign key name "' . $thing->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".');
$logger->error('Foreign key name "' . $thing->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".');
}
$constraintNames[$thing->getName()] = $table->getName();
}
Expand All @@ -688,15 +691,15 @@ public function ensureUniqueNamesConstraints(Schema $targetSchema): void {
}

if (isset($constraintNames[$indexName])) {
throw new \InvalidArgumentException('Primary index name "' . $indexName . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".');
$logger->error('Primary index name "' . $indexName . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".');
}
$constraintNames[$indexName] = $table->getName();
}
}

foreach ($sequences as $sequence) {
if (isset($constraintNames[$sequence->getName()])) {
throw new \InvalidArgumentException('Sequence name "' . $sequence->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".');
$logger->error('Sequence name "' . $sequence->getName() . '" for table "' . $table->getName() . '" collides with the constraint on table "' . $constraintNames[$thing->getName()] . '".');
}
$constraintNames[$sequence->getName()] = 'sequence';
}
Expand Down

0 comments on commit 1e4cf27

Please sign in to comment.