@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user