Skip to content

Commit 2279628

Browse files
authored
Merge pull request plausible#3 from coingaming/cluster-opt
Allow to create/drop DB on cluster
2 parents 12a498e + e133a55 commit 2279628

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lib/clickhouse_ecto/storage.ex

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ defmodule ClickhouseEcto.Storage do
77

88
opts = Keyword.put(opts, :database, nil)
99

10-
command = ~s[CREATE DATABASE IF NOT EXISTS "#{database}"]
10+
cluster = Keyword.get(opts, :cluster)
11+
12+
opts = Keyword.put(opts, :database, nil)
13+
14+
command =
15+
if is_nil(cluster) do
16+
~s[CREATE DATABASE IF NOT EXISTS "#{database}"]
17+
else
18+
~s[CREATE DATABASE IF NOT EXISTS "#{database}" ON CLUSTER '#{cluster}']
19+
end
1120

1221
case run_query(command, opts) do
1322
{:ok, _} ->
@@ -26,7 +35,15 @@ defmodule ClickhouseEcto.Storage do
2635
database =
2736
Keyword.fetch!(opts, :database) || raise ":database is nil in repository configuration"
2837

29-
command = ~s[DROP DATABASE "#{database}"]
38+
cluster = Keyword.get(opts, :cluster)
39+
40+
command =
41+
if is_nil(cluster) do
42+
~s[DROP DATABASE "#{database}"]
43+
else
44+
~s[DROP DATABASE "#{database}" ON CLUSTER '#{cluster}']
45+
end
46+
3047
opts = Keyword.put(opts, :database, nil)
3148

3249
case run_query(command, opts) do

0 commit comments

Comments
 (0)