Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/RedshiftConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function createConnection($dsn, array $config, array $options)
// is useful for automation tests that bypass the connection process.

if (! empty($config['password'])) {
return parent::createConnection($dsn, $config, $options);
return $this->customConnection($dsn, $config, $options);
}

$execute = function (int $attempt) use ($dsn, $config, $options) {
Expand All @@ -52,11 +52,26 @@ public function createConnection($dsn, array $config, array $options)

$config['password'] = $this->password->resolve($config['redshift']['secret'], $freshSecret);

return parent::createConnection($dsn, $config, $options);
return $this->customConnection($dsn, $config, $options);
};

$condition = fn (Exception $e) => $e instanceof PDOException && str_contains($e->getMessage(), 'Access denied for user');

return retry(when: $condition, callback: $execute, times: 3);
}

private function customConnection($dsn, array $config, array $options): \PDO
{
$connection = parent::createConnection($dsn, $config, $options);

$timezone = $config['timezone'] ?? null;

// Redshift does not support connect on timezone using DSN,
// only through SET timezone {timezone}
if ($timezone) {
$connection->exec("SET timezone TO $timezone");
}

return $connection;
}
}