plausible / ecto_ch

Ecto ClickHouse adapter
MIT License
72 stars 10 forks source link

add: support for ON CLUSTER #115

Closed edwardsmit closed 1 year ago

edwardsmit commented 1 year ago

I need to have the schema_migrations and all tables for my app get created with ON CLUSTER our-cluster to ensure that the tables get replicated from the start.

As I can't use the :options section in Ecto.Migrations.Table, because that is expected to be a String in this adapter, I've opted to use the Application Environment for configuring the :cluster_name.

Any feedback, positive or negative is appreciated.

ruslandoga commented 1 year ago

👋 @edwardsmit

:options being a string is just me being lazy. It's probably about time to try and add all options ClickHouse supports :) I'll try doing that tomorrow.

As for app env, I'd prefer to keep it only for defaults-like options (like :default_table_engine, etc.)

I wonder if there is any place we can pass :options for the schema_migrations table. I'll try looking for it tomorrow as well. If there isn't one, we'll have to use app env, I have something like this in mind

config :ecto_ch,
  schema_migrations: [on_cluster: "our-cluster", engine: "MergeTree", order_by: "tuple()"]

Ideally we'd be able to scope it per Ecto repo.

edwardsmit commented 1 year ago

👋🏼 @ruslandoga I looked for :options specific for the schema_migrations_table but couldn't find it. That's how I ended up creating this PR, as I could use a custom SQL-string for the migrations themselves. It would be great to be able to configure as outlined by you. I will do some digging myself as well, to see if we can address the special case of schema_migrations.

ruslandoga commented 1 year ago

👋 @edwardsmit

I made some changes to migrations today, I wonder if they resolve your issue. The most relevant PRs are https://github.com/plausible/ecto_ch/pull/116 and https://github.com/plausible/ecto_ch/pull/123.

Now, to have schema_migrations and all other tables for your app created with ON CLUSTER our-cluster, you can set :default_table_options in app env like this

config :ecto_ch, default_table_options: [cluster: "our-cluster"]

These default options are merged with table.options in table/2 provided table.options is a keyword list.


UPDATE: I published the current master as v0.3.0

edwardsmit commented 1 year ago

Closing in favour of #116 and #123