We have a pretty standard Phoenix app here which uses a bin/migrate
file (basically exec ./myapp eval Myapp.Release.migrate
) to run migrations before releasing a new version.
For some reason I am getting this error when starting the migration (after the update to Elixir 1.15.0):
ERROR! Config provider Config.Reader failed with:
** (ArgumentError) could not fetch application environment :always_evaluate_messages for application :logger because the application was not loaded nor configured
(elixir 1.15.0) lib/application.ex:775: Application.fetch_env!/2
lib/logger.ex:1012: Logger.macro_log/4
expanding macro: Logger.warning/1
/app/releases/0.1.0/runtime.exs:212: (file)
(elixir 1.15.0) expanding macro: Kernel.if/2
/app/releases/0.1.0/runtime.exs:211: (file)
(elixir 1.15.0) expanding macro: Kernel.if/2
/app/releases/0.1.0/runtime.exs:48: (file)
{"init terminating in do_boot",{#{'__exception__'=>true,'__struct__'=>'Elixir.ArgumentError',message=><<"could not fetch application environment :always_evaluate_messages for application :logger because the application was not loaded nor configured">>},[{'Elixir.Application','fetch_env!',2,[{file,"lib/application.ex"},{line,775}]},{'Elixir.Logger',macro_log,4,[{file,"lib/logger.ex"},{line,1012}]},{'Elixir.Logger',warning,1,[{file,"expanding macro"}]},{elixir_compiler_0,'__FILE__',1,[{file,"/app/releases/0.1.0/runtime.exs"},{line,212}]},{'Elixir.Kernel',if,2,[{file,"expanding macro"}]},{elixir_compiler_0,'__FILE__',1,[{file,"/app/releases/0.1.0/runtime.exs"},{line,211}]},{'Elixir.Kernel',if,2,[{file,"expanding macro"}]},{elixir_compiler_0,'__FILE__',1,[{file,"/app/releases/0.1.0/runtime.exs"},{line,48}]}]}}
init terminating in do_boot ({,[{Elixir.Application,fetch_env!,2,[{_},{_}]},{Elixir.Logger,macro_log,4,[{_},{_}]},{Elixir.Logger,warning,1,[{_}]},{elixir_compiler_0,__FILE__,1,[{_},{_}]},{Elixir.Kernel,if,2,[{_}]},{elixir_compiler_0,__FILE__,1,[{_},{_}]},{Elixir.Kernel,if,2,[{_}]},{elixir_compiler_0,__FILE__,1,[{_},{_}]}]})
The Myapp.Release
module looks like this:
defmodule Myapp.Release do
@moduledoc """
Used for executing DB release tasks when run in production without Mix
installed.
"""
@app :myapp
require Logger
def migrate do
load_app()
for repo <- repos() do
# Ensure the repo is started. Then, if the "schema_migrations"
# table does not exist, run the `structure.sql` file for the repo.
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &check_and_execute_structure_sql(&1))
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
end
end
def rollback(repo, version) do
load_app()
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
end
defp check_and_execute_structure_sql(repo) do
config = repo.config()
app_name = Keyword.fetch!(config, :otp_app)
if Ecto.Adapters.SQL.table_exists?(repo, "schema_migrations") do
Logger.info("schema_migrations table already exists")
:ok
else
case repo.__adapter__().structure_load(
Application.app_dir(app_name, "priv/repo"),
repo.config()
) do
{:ok, location} = success ->
Logger.info("The structure for #{inspect(repo)} has been loaded from #{location}")
success
{:error, term} when is_binary(term) ->
Logger.error("The structure for #{inspect(repo)} couldn't be loaded: #{term}")
{:error, inspect(term)}
{:error, term} ->
Logger.error("The structure for #{inspect(repo)} couldn't be loaded: #{inspect(term)}")
{:error, inspect(term)}
end
end
end
defp repos do
Application.fetch_env!(@app, :ecto_repos)
end
defp load_app do
Application.load(@app)
end
end
I seem to understand what the error is, but I have no clue what to do about it. Can somebody give me a nudge in the right direction?