Skip to content

Commit

Permalink
Add lowercase role name support
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrajodas committed Feb 4, 2025
1 parent 3300a40 commit 9d1399d
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9d1399d

Please sign in to comment.