Skip to content

Commit

Permalink
grant role if not granted
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrajodas committed Nov 5, 2024
1 parent 6c0f2d3 commit e6248b7
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/Cleanup.php
Original file line number Diff line number Diff line change
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 e6248b7

Please sign in to comment.