From 6c0f2d36f883b86ee333d2b01db5fd0286c16498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Jodas?= Date: Tue, 5 Nov 2024 22:44:39 +0100 Subject: [PATCH 1/2] fix typo --- src/Cleanup.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cleanup.php b/src/Cleanup.php index 16a717f..9212d15 100644 --- a/src/Cleanup.php +++ b/src/Cleanup.php @@ -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, ); From e6248b780e0a177c2920a0f3a4294689783dadcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Jodas?= Date: Tue, 5 Nov 2024 22:46:06 +0100 Subject: [PATCH 2/2] grant role if not granted --- src/Cleanup.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Cleanup.php b/src/Cleanup.php index 9212d15..29ac404 100644 --- a/src/Cleanup.php +++ b/src/Cleanup.php @@ -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(