diff --git a/src/RedshiftConnector.php b/src/RedshiftConnector.php index b3bf078..42bc392 100644 --- a/src/RedshiftConnector.php +++ b/src/RedshiftConnector.php @@ -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) { @@ -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; + } }