Ecto 3 pool_size dynamic in distillary

Previously when I deploy apps to prod, I would provide

pool_size: "${DB_POOL_SIZE}"

But after upgrade to ecto 3

no match of right hand side value: {:error, {:EXIT, {%ArgumentError{message: "ranges (first..last) expect both sides to be integers, got: 1..\"10\""}, [{Range, :new, 2, [file: 'lib/range.ex', line: 55]}, {DBConnection.ConnectionPool.Pool, :start_link, 4, [file: 'lib/db_connection/connection_pool/pool.ex', line: 6]}, {:supervisor, :do_start_child_i, 3, [file: 'supervisor.erl', line: 379]}, {:supervisor, :handle_call, 3, [file: 'supervisor.erl', line: 404]}, {:gen_server, :try_handle_call, 4, [file: 'gen_server.erl', line: 661]}, {:gen_server, :handle_msg, 6, [file: 'gen_server.erl', line: 690]}, {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 249]}]}}}

I am getting parse error. As you see, ecto got "10\" as pool_size instead of integer 10. How can I provide pool_size dynamically to repo configs, if ecto doesnt support string pool_size?

The problem is that you are passing the pool_size as a string but Ecto expects an integer. What happens if you do pool_size: ${DB_POOL_SIZE}? Or pool_size: String.to_integer("${DB_POOL_SIZE}").

1 Like
pool_size: "DB_POOL_SIZE" |> System.get_env() |> String.to_integer()

with a distillery’s config provider would probably work as well.

1 Like

I tried pool_size: ${DB_POOL_SIZE} and I got above error. I solved this problem by overriding pool_size in repo config

def init(_type, config) do
  if Application.get_env(:dealor_data_layer, :env) == :prod do
    pool_size =
        Application.get_env(:dealor_data_layer, DealorDataLayer.Repo)[:pool_size]

    {:ok, Keyword.put(config, :pool_size, pool_size)}
    {:ok, config}

Thanks for your reply