How to configure Ecto at runtime?

只谈情不闲聊 提交于 2019-12-01 22:21:04

问题


Following the setup instructions, I have the following Ecto configuration in my config/config.exs file :

config :my_app, MyApp.Repo,
  adapter: Ecto.Adapters.Postgres,
  url: "postgresql://postgres@localhost/myrepo",
  size: 20

If my understanding is correct, the config.exs is evaluated at compile-time.

Is there a way to do this configuration step at runtime ?

This is for an app which will be distributed as a compiled binary (via exrm). The end-user should be able to customize the database url and pool size via flags or environment variables, not by editing sys.config


回答1:


Loading from the system is possible by using {:system, "KEY" } e.g.:

config :my_app Repo
   url: {:system, "DATABASE_URL" },
   size: {:system, "DATABASE_POOL_SIZE" }

instead

config :my_app, Repo,
   url: "ecto://postgres:postgres@localhost/ecto_simple",
   size: 20

In this case you set up Ecto to use the system properties. Of course, a user has to configure it.



来源:https://stackoverflow.com/questions/37283387/how-to-configure-ecto-at-runtime

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!