plausible / community-edition

Example Docker Compose setup for hosting Plausible Community Edition
1.44k stars 303 forks source link

Trying to run migration on Clickhouse Cloud fails. #164

Closed arvaizo closed 1 month ago

arvaizo commented 1 month ago

When Running the migration it seems plausible assumes that the database is distributed or not by looking at the system.replicas table. After making that assumption it is trying to use the {cluster} macro which is not present on Clickhouse Cloud anymore. As such the migrations relying on that field are failing.

Did anybody manage to work-around this issue?

** (Ch.Error) Code: 139. DB::Exception: No macro 'cluster' in config while processing substitutions in '{cluster}' at '1' or macro is not supported here. (NO_ELEMENTS_IN_CONFIG) (version 24.6.1.4472 (official build))

    (ecto_sql 3.12.0) lib/ecto/adapters/sql.ex:1078: Ecto.Adapters.SQL.raise_sql_call_error/1
    (elixir 1.17.1) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
    (ecto_sql 3.12.0) lib/ecto/adapters/sql.ex:1185: Ecto.Adapters.SQL.execute_ddl/4
    (ecto_sql 3.12.0) lib/ecto/migration/runner.ex:348: Ecto.Migration.Runner.log_and_execute_ddl/3
    (elixir 1.17.1) lib/enum.ex:1703: Enum."-map/2-lists^map/1-1-"/2
    (stdlib 6.0) timer.erl:590: :timer.tc/2
    (ecto_sql 3.12.0) lib/ecto/migration/runner.ex:25: Ecto.Migration.Runner.run/8
 ~/Projects/monolith/plausible.k8s ξ‚° 
ruslandoga commented 1 month ago

πŸ‘‹ @arvaizo

One way to work around this would be to create the required tables "manually", with the appropriate ON CLUSTER, ENGINE, etc. clauses, and populate schema_migrations table to avoid running them from Plausible.

arvaizo commented 1 month ago

πŸ‘‹ @arvaizo

One way to work around this would be to create the required tables "manually", with the appropriate ON CLUSTER, ENGINE, etc. clauses, and populate schema_migrations table to avoid running them from Plausible.

Thanks @ruslandoga, unfortunately that SQL script does not execute as only replicated tables can be created within Clickhouse cloud. Also there is some runtime code that depends on the "cluster" macro being there (DebugController). Finally there are some settings like index_granularity that does not seem to be supported either.

ruslandoga commented 1 month ago

You would need to modify the default SQL statements to fit your needs :) Once you run them, you can remove /entrypoint.sh db migrate and Plausible will skip migrations.