Closed smahi closed 2 years ago
Yes, the seeds file is only in the priv
directory, those are not compiled into the app. You can move it to lib
if you want to call it inside your production code.
Sorry, I can't help with the missing module. Maybe someone can figure it out if you put the code of your module.
But I can show you an alternative. This is what I've done for my apps. After I use mix phx.gen.release --docker
command, I add the following lines to my lib/<otp_app>/release.ex
file:
def seed do
load_app()
for repo <- repos() do
{:ok, _, _} =
Ecto.Migrator.with_repo(repo, fn repo ->
# Run the seed script if it exists
seed_script = priv_path_for(repo, "seeds.exs")
if File.exists?(seed_script) do
IO.puts("Running seed script..")
Code.eval_file(seed_script)
end
end)
end
end
defp priv_path_for(repo, filename) do
app = Keyword.get(repo.config(), :otp_app)
repo_underscore =
repo
|> Module.split()
|> List.last()
|> Macro.underscore()
priv_dir = "#{:code.priv_dir(app)}"
Path.join([priv_dir, repo_underscore, filename])
end
and then I'm able to use those inside the rel/overlays/bin/migrate
file:
#!/bin/sh
cd -P -- "$(dirname -- "$0")"
exec ./sase_mango eval 'SaseMango.Release.migrate && SaseMango.Release.seed'
Environment
Expected behavior
Compile
Utmaktaba.Prod.Seeds
module to be available in production releaseActual behavior
When releasing Phoenix app using
mix phx.gen.release --docker
in production env, the module would not be compiled for some reason!!! But using normal release (without using docker) the module is compiled and loaded.Its throw the following errors
This is my mix file