<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="33603" data-post-id="33603">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="josevalim" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/120/1787_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  josevalim
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Creator of Elixir</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="cjbottaro" data-post="21" data-topic="4423">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cjbottaro/48/1469_2.png" class="avatar"> cjbottaro:</div>
<blockquote>
<p>Can you explain a bit more?  As far as I can tell, Ecto is configured using Mix.Config and a config.exs file.</p>
</blockquote>
</aside>
<p>The changes happen on two different levels.</p>
<p>Internally: it means that Ecto will internally expect configurations to be set at runtime rather than compile time.</p>
<p>Externally: it means that Ecto will provide a proper API to do runtime configuration. The only way to do runtime configuration in Ecto 2.0 was by using <code>url: {:system, "DATABASE_URL"}</code> which has two big problems: it only works for the <code>:url</code> parameter and it only allows the configuration to be read from the system environment. If you need to read it from elsewhere, you are out of luck.</p>
<p>Ecto 2.1 now provides the init/2 callback inside your repo for runtime configuration:</p>
<pre><code>def init(_, config) do
  {:ok, Keyword.put(config, :url, System.get_env("DATABASE_URL"))}
end
</code></pre>
<p>Now you have the flexibility to do whatever you want. Also note Ecto allows the configuration to be given at the moment you call start_link on the Repo.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="33603" data-batch-url="/posts/batch_likers">
                        5
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/mix-config-evolutions/4423/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-33603" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="33603"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-most-liked cat-most-liked" title="One of the top 3 liked posts in this thread!"></div>
  </section>
</div>
    <div class="postbit" id="39615" data-post-id="39615">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="tompave" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/tompave/120/4142_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  tompave
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi, I have a few questions on the direction that’s been mentioned above.</p>
<aside class="quote group-livebook_core_team quote-modified" data-username="josevalim" data-post="8" data-topic="4423">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>For example, no configuration library that will solve the compile-time issues we have today.[/quote]<br>
Ok, but does this mean that <code>Application.get_env/2</code> and the <code>ac_tab</code> ETS table should never be used for runtime configuration?</p>
<p>[quote=“josevalim, post:8, topic:4423”]The solution is for libraries to rely less on compile-time configuration and document when it happens. We have also tried to make {:system, env} work but, at this point, it is clear that runtime configuration should be moved to runtime. It doesn’t work in Elixir nor did it work on Erlang.</p>
</blockquote>
</aside>
<p>The two problems I’ve found so far with <code>{:system, "MY_VAR"}</code> are that:</p>
<ul>
<li>it’s not standard and requires custom code (that people are extracting in libraries)</li>
<li>Reading with <code>System.get_env("MY_VAR")</code> is slower than reading from the Application env (but benchmarks show that caching it in the wrapper speeds thing up).</li>
</ul>
<p>Both problems could be solved by adding a layer between the Elixir API and the underlying Erlang calls.</p>
<p>So I guess that a different way to frame the problem is that we have a centralized configuration API that does not currently support runtime configuration, which is a common requirement, as opposed to saying that “runtime configuration should be moved to runtime”.</p>
<aside class="quote group-livebook_core_team" data-username="josevalim" data-post="19" data-topic="4423">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/48/1787_2.png" class="avatar"> josevalim:</div>
<blockquote>
<p>Rely less on compile-time configs and more on arguments. The application environment is global configuration and therefore it can be prone to conflicts.</p>
</blockquote>
</aside>
<p>I can see how this would work when starting supervisors and processes. If a dependency requires configuration (e.g. API tokens, URLs, flags, etc), they can be read from the ENV and passed to the supervision tree, then something will either store the config in a GenServer’s state or a ETS table, depending on how frequently it needs to be accessed. (please correct me if I’m wrong)<br>
I am not sure how it would work for libraries that don’t start processes though.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="39615" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/mix-config-evolutions/4423/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-39615" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="39615"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #22"></div>
  </section>
</div>
    <div class="postbit" id="171926" data-post-id="171926">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="i-n-g-m-a-r" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  i-n-g-m-a-r
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><code>init</code> runtime configuration only works for supervised dependencies, it will not work for things like:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  plug Plug.Session,
    signing_salt: "how to manage this setting"
</code></pre>
<p>Maybe applications could accept a module instead of values (or both) ?</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  plug Plug.Session,
    handler: MyApp.MyConfigHandler
</code></pre>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule MyApp.MyConfigHandler do
  # use MyApp.CompileTimeSettings
  def setting({:plug, :session, :cookie, :signing_salt}) do
    # - "very secret signing salt"
    # - System.get_env("COOKIE_SIGNING_SALT")
    # - MyExternalServiceAPI.get(:signing_salt)
    # - or whatever
  end

  def setting(tuple) do
    IO.inspect tuple, label: "Show me available settings"
    nil
  end
end
</code></pre>
<p>I would be very happy to be able to configure my dependencies this way.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="171926" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/mix-config-evolutions/4423/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-171926" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="171926"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>