Skip to content

Commit

Permalink
Merge pull request #44 from keboola/ondra-fix-typo
Browse files Browse the repository at this point in the history
Minor cleanup changes
  • Loading branch information
ondrajodas authored Nov 6, 2024
2 parents 281925e + e6248b7 commit 417961b
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function preMigration(string $mainRoleName): void

$hasMainRoleOwnership = array_reduce(
$mainRole,
fn ($found, $v) => $found || $v['owner'] === $this->config->getTargetSnowflakeUser(),
fn ($found, $v) => $found || $v['owner'] === $this->config->getTargetSnowflakeRole(),
false,
);

Expand Down Expand Up @@ -157,13 +157,20 @@ public function preMigration(string $mainRoleName): void
}
$this->destinationConnection->useRole($mainRoleName);
if ($currentRole === $mainRoleName && !$mainRoleExistsOnTargetUser) {
$this->destinationConnection->query(sprintf(
'GRANT ROLE %s TO USER %s;',
Helper::quoteIdentifier($currentRole),
Helper::quoteIdentifier($this->config->getTargetSnowflakeUser())
));
$this->destinationConnection->grantRoleToUser(
$this->config->getTargetSnowflakeUser(),
$currentRole,
);
}
try {
$this->destinationConnection->useRole($role['granted_by']);
} catch (RuntimeException $e) {
$this->destinationConnection->grantRoleToUser(
$this->config->getTargetSnowflakeUser(),
$role['granted_by'],
);
$this->destinationConnection->useRole($role['granted_by']);
}
$this->destinationConnection->useRole($role['granted_by']);

/** @var FutureGrantToRole[] $futureGrants */
$futureGrants = array_map(
Expand Down

0 comments on commit 417961b

Please sign in to comment.