Skip to content

Commit

Permalink
fix: 🐛 cluster detection
Browse files Browse the repository at this point in the history
not using table because table on first migration never exists!
  • Loading branch information
karlosmid committed Jan 8, 2025
1 parent 5e6ccde commit 6f30a4f
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/plausible/migration_utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ defmodule Plausible.MigrationUtils do
Base module for to use in Clickhouse migrations
"""

def on_cluster_statement(table) do
if(clustered_table?(table), do: "ON CLUSTER '#{cluster_name()}'", else: "")
end

def clustered_table?(table) do
case Plausible.IngestRepo.query("SELECT 1 FROM system.replicas WHERE table = '#{table}'") do
{:ok, %{rows: []}} -> false
{:ok, _} -> true
def on_cluster_statement(_table) do
case cluster_name() do
{:ok, cluster} -> "ON CLUSTER '#{cluster}'"
_ -> ""
end
end

Expand Down

0 comments on commit 6f30a4f

Please sign in to comment.