You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fail to run migration when default_table_options is set #4454
I have searched open and closed issues to make sure that the bug has not yet been reported
Issue is a Bug Report
This is a bug report and not a feature request, nor asking for self-hosted support
Using official Plausible Cloud hosting or self-hosting?
Self-hosting
Describe the bug
I overrided default_table_options to configure Plausible to generate Replicated* tables and execute DDL statement with ON CLUSTER clause.
Here is the config I set in a file pointed to by EXTRA_CONFIG_PATH
When I run migrations with /entrypoint.sh db migrate I get the following error:
Loading plausible..
Starting dependencies..
Starting repos..
Running migrations for Elixir.Plausible.Repo
Running migrations for Elixir.Plausible.IngestRepo
warning: code block contains unused literal "Migration adds a ALIAS columns needed to keep DB schema and api\nproperty naming in sync to reduce overhead in code.\n" (remove the literal or assign it to _ to avoid warnings)
└─ lib/plausible-0.0.1/priv/ingest_repo/migrations/20240502115822_alias_api_prop_names.exs: Plausible.IngestRepo.Migrations.AliasApiPropNames (module)
** (ArgumentError) expected a keyword list as the second argument, got: ["PARTITION BY toYYYYMM(timestamp) ORDER BY (domain, toDate(timestamp), user_id) SETTINGS index_granularity = 8192"]
(elixir 1.16.0) lib/keyword.ex:999: Keyword.merge/2
(ecto_ch 0.3.5) lib/ecto/adapters/clickhouse/migration.ex:177: Ecto.Adapters.ClickHouse.Migration.table/1
(ecto_ch 0.3.5) lib/ecto/adapters/clickhouse/migration.ex:17: Ecto.Adapters.ClickHouse.Migration.execute_ddl/1
(ecto_sql 3.11.1) lib/ecto/adapters/sql.ex:1159: Ecto.Adapters.SQL.execute_ddl/4
I guess the fix for this could be to rewrite all Ecto migrations to use keyword options, but then it would still not achieve your goals since we also have a separate way of migrating (using templated raw sql) which doesn't use Ecto migrations and as such would't use ecto_ch default options.
Ok. So there is really no way to get an HA Clickhouse setup with Plausible ?
Can we generate plain HTML from migrations some way or another so that we can at least edit the SQL manually ?
AFAIK Plausible Cloud runs HA ClickHouse setup so it should be possible without any changes to the codebase. There are some helper functions sprinkled throughout like Plausible.IngestRepo.clustered_table?: https://github.com/search?q=repo%3Aplausible%2Fanalytics%20cluster&type=code - and they do most of the work. I guess you'd need to somehow "bootstrap" the cluster and some initial tables and from there Plausible would keep doing the right thing for the new tables.
Make sense that CE is not targeting big deployment.
I built a solution in the form of an HTTP proxy that rewrite DDL statements on the fly to rewrite CREATE TABLE queries.
It's working fine on v2.1.0 and v2.1.1 so it might be useful to the community.
Activity
ruslandoga commentedon Aug 21, 2024
👋 @arnaudbriche
The error means that we can't merge default keyword options like
[{:cluster, "default"}]with the raw options provided in the migrations like"PARTITION BY toYYYYMM(timestamp) ORDER BY (domain, toDate(timestamp), user_id) SETTINGS index_granularity = 8192"in https://github.com/plausible/analytics/blob/master/priv/ingest_repo/migrations/20200915070607_create_events_and_sessions.exs#L12-L14.I guess the fix for this could be to rewrite all Ecto migrations to use keyword options, but then it would still not achieve your goals since we also have a separate way of migrating (using templated raw sql) which doesn't use Ecto migrations and as such would't use
ecto_chdefault options.arnaudbriche commentedon Aug 21, 2024
Hi @ruslandoga
Ok. So there is really no way to get an HA Clickhouse setup with Plausible ?
Can we generate plain HTML from migrations some way or another so that we can at least edit the SQL manually ?
ruslandoga commentedon Aug 21, 2024
AFAIK Plausible Cloud runs HA ClickHouse setup so it should be possible without any changes to the codebase. There are some helper functions sprinkled throughout like
Plausible.IngestRepo.clustered_table?: https://github.com/search?q=repo%3Aplausible%2Fanalytics%20cluster&type=code - and they do most of the work. I guess you'd need to somehow "bootstrap" the cluster and some initial tables and from there Plausible would keep doing the right thing for the new tables.arnaudbriche commentedon Aug 21, 2024
Yes. I see a lot of this in the code:
But there is literally no documented way to set this
clustervariable.Can anyone provide assistance ?
ruslandoga commentedon Aug 21, 2024
It's not documented since Plausible CE is mostly geared towards simple, single-host deployments for the sake of simplicity and easy of use :)
I think you can try creating the tables manually (with the correct CLUSTER options) from (outdated) https://github.com/plausible/analytics/blob/master/priv/ingest_repo/structure.sql and then starting Plausible and running automated migrations.
arnaudbriche commentedon Aug 21, 2024
Make sense that CE is not targeting big deployment.
I built a solution in the form of an HTTP proxy that rewrite DDL statements on the fly to rewrite CREATE TABLE queries.
It's working fine on v2.1.0 and v2.1.1 so it might be useful to the community.
https://github.com/arnaudbriche/plausible-ddl-proxy