Mix.Tasks.Run works in test but crashes in prod

Hi all.

I’m using Elixir/Phoenix v1.2.1.
Production Server is Ubuntu 16.04.2 LTS (AWS)
Test Server is Ubuntu 16.04.2 LTS (Azure)
DB Server is MySQL.

I created a task (priv/repo/reset_units.exs) that is supposed to run a DB update on server startup. Its code is simple as follows:

alias Myserver.Repo
alias Myserver.MyUnit

Repo.update_all(MyUnit, set: [online: false])

I also changed the start/2 function of lib/Myserver.ex including this:

Logger.info ("[INIT] DB table updated.")

It runs fine on test server, but when I build the release and try to start it on production I get the following exception

[info] Application myserver exited: exited in: myserver.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function Mix.Tasks.Run.run/1 is undefined (module Mix.Tasks.Run is not available)
            (myserver) lib/myserver.ex:29: myserver.start/2
            (kernel) application_master.erl:273: :application_master.start_it_old/4

Does anybody had a similar issue?


You have code that is trying to access Mix somwhere, but Mix is the build system that is only available in the build area, it is not available in a release. Don’t use Mix from user code.

Got it, thanks.
Any suggestion on how I can I run that DB update on server startup?

Ecto has a Migration api to do that. That is what the mix ecto.migrate command ends up calling in to, just gotta do it yourself manually instead. :slight_smile: