There is a way to set @schema_prefix at runtime?

I have a project that uses Ecto, so I have many schemas one by environment (3 environment), on that schemas we currently use @schema_prefix.

Nowadays I compile my project for each environment, but I want to compile my aplication on a single time and load all settings at runtime, for this I need to pass this value dinamically for example with Application.get_env(:my_app, :ecto_schema)

There is a way to set @schema_prefix at runtime? Or I always should to compile for different schemas.

Hello and welcome!

Module attributes are compile-time constructs so you can’t set them at runtime (they no longer even exist at runtime).

Sorry I don’t have a direct answer, but you might be able to find some inspiration for your problem here.

2 Likes

A good amount of Ecto.Repo functions accept the prefix parameter f.ex. insert.

5 Likes