parent
f3509f2a17
commit
f5e15941de
@ -0,0 +1,12 @@
|
||||
defmodule Plausible.MigrationUtils do
|
||||
@moduledoc """
|
||||
Base module for to use in Clickhouse migrations
|
||||
"""
|
||||
|
||||
def on_cluster_statement(table) do
|
||||
case Plausible.IngestRepo.query("SELECT 1 FROM system.replicas WHERE table = '#{table}'") do
|
||||
{:ok, %{rows: []}} -> ""
|
||||
{:ok, _} -> "ON CLUSTER '{cluster}'"
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,25 @@
|
||||
defmodule Plausible.IngestRepo.Migrations.MinmaxIndexSessionTimestamp do
|
||||
use Ecto.Migration
|
||||
|
||||
def up do
|
||||
execute """
|
||||
ALTER TABLE sessions_v2
|
||||
#{Plausible.MigrationUtils.on_cluster_statement("sessions_v2")}
|
||||
ADD INDEX IF NOT EXISTS minmax_timestamp timestamp
|
||||
TYPE minmax GRANULARITY 1
|
||||
"""
|
||||
|
||||
execute """
|
||||
ALTER TABLE sessions_v2
|
||||
MATERIALIZE INDEX minmax_timestamp
|
||||
"""
|
||||
end
|
||||
|
||||
def down do
|
||||
execute """
|
||||
ALTER TABLE sessions_v2
|
||||
#{Plausible.MigrationUtils.on_cluster_statement("sessions_v2")}
|
||||
DROP INDEX IF EXISTS minmax_timestamp
|
||||
"""
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue