From 9d1399df9731adae6d776c8eb4fe1b44698f08de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Jodas?= Date: Tue, 4 Feb 2025 23:21:03 +0100 Subject: [PATCH] Add lowercase role name support --- src/Cleanup.php | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Cleanup.php b/src/Cleanup.php index 309d6cb..55f04cb 100644 --- a/src/Cleanup.php +++ b/src/Cleanup.php @@ -140,17 +140,25 @@ public function preMigration(string $mainRoleName): void if (!$dbExists) { $this->logger->info(sprintf('Database %s does not exist, checking for role with same name', $database)); - // If database doesn't exist, check if there's a role with the same name - $roleExists = $this->destinationConnection->fetchAll(sprintf( - 'SHOW ROLES LIKE %s;', - QueryBuilder::quote($database) - )); + // Check if role exists with exact or lowercase name + $roleName = null; + foreach ([$database, strtolower($database)] as $nameVariant) { + $roleExists = $this->destinationConnection->fetchAll(sprintf( + 'SHOW ROLES LIKE %s', + QueryBuilder::quote($nameVariant) + )); + if ($roleExists) { + $roleName = $nameVariant; + break; + } + } - if (!$roleExists) { + if ($roleName === null) { continue; } - $dataToRemove = $this->getDataToRemove($this->destinationConnection, $database); - $roleToRemove = $database; + + $dataToRemove = $this->getDataToRemove($this->destinationConnection, $roleName); + $roleToRemove = $roleName; } else { $this->logger->info(sprintf('Database %s exists, getting ownership role', $database)); $databaseRole = $this->destinationConnection->getOwnershipRoleOnDatabase($database);