algoliax icon indicating copy to clipboard operation
algoliax copied to clipboard

How to set index_name for separate environments

Open ringvold opened this issue 8 months ago • 0 comments

Hi,

I'm having some challenges figuring out how to handle multiple indices for different environments and looking for some tips.

As index_name is a part of the configuration when using the Algoliax.Indexer macro the index name needs to be set at compile time. Often variables that can differ between environments are set as environment variables at startup/runtime as one would have a separate index for each environment.

For now I have used if(Mix.env() == :prod, do: :prod_index_name, else: :dev_index_name) which is fine for a while but when we need to introduce a staging environment which would have the same mix env as production.

I hoped there was a way to do this with environment variables but I cant see how as it is required at compile time.

One alternative would be to create one module per environment and use config to select between them but I hoped it would be a better way to handle it.

Does anyone use this library with multiple environments and different index names or have any tips of how to handle this?

Are there any plans to change this or would you consider changing how index_names can be provided to support using environment variables?

ringvold avatar Jun 14 '24 16:06 ringvold