From 2f2037f4da280ebf25d926be135a2fd9d0f8964e Mon Sep 17 00:00:00 2001 From: janis steiner Date: Sun, 31 May 2026 20:48:22 +0200 Subject: [PATCH] fix migration --- src/Storage/ClickHouseClient.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Storage/ClickHouseClient.php b/src/Storage/ClickHouseClient.php index 6847b37..7e7248a 100644 --- a/src/Storage/ClickHouseClient.php +++ b/src/Storage/ClickHouseClient.php @@ -167,7 +167,26 @@ class ClickHouseClient public function migrate(): void { - $this->execute("CREATE DATABASE IF NOT EXISTS {$this->database}"); + $ch = curl_init(); + curl_setopt_array($ch, [ + CURLOPT_URL => $this->url() . '?' . http_build_query(['database' => 'default']), + CURLOPT_POST => true, + CURLOPT_POSTFIELDS => "CREATE DATABASE IF NOT EXISTS {$this->database}", + CURLOPT_RETURNTRANSFER => true, + CURLOPT_TIMEOUT => $this->timeout, + CURLOPT_CONNECTTIMEOUT => $this->timeout, + CURLOPT_HTTPHEADER => ['Content-Type: text/plain'], + ]); + if ($this->username) { + curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + curl_setopt($ch, CURLOPT_USERPWD, $this->username . ':' . $this->password); + } + $response = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + curl_close($ch); + if ($httpCode !== 200 && !str_contains($response, 'already exists')) { + throw new \RuntimeException("ClickHouse error (HTTP $httpCode): $response"); + } $this->execute(" CREATE TABLE IF NOT EXISTS log_entries (