When trying to run the seeds file from a release, I am getting a "could not lookup MyApp.Repo" error

I need to run a seed file on new containers in a kubernetes cluster with every deploy. I am trying to follow the instructions that I found on the post below from 6 years ago. Yet when I run the command, I am getting this error

could not lookup Ecto repo MyApp.Repo because it was not started or it does not exist

I am making sure to run Application.ensure_loaded(@app) in the function that attempts to execute the seeds script.

So I am wondering if something changed or I am somehow making a mistake when I am trying to run the script. Here is the code

  def seed do
    load_app()
    Application.ensure_loaded(@app)
    Ecto.Migrator.with_repo(MyApp.Repo, eval_seed())
  end

  def eval_seed do
    seed_path = get_seed_path()
    Code.eval_file(seed_path)
  end

  def get_seed_path() do
    priv_dir = "#{:code.priv_dir(@app)}"
    Path.join([priv_dir, "repo/", "seeds.exs"])
  end

Any ideas?

I found the problem.

 Ecto.Migrator.with_repo(MyApp.Repo, eval_seed())

is a mistake. It should be

Ecto.Migrator.with_repo(MyApp.Repo, fn _repo → eval_seed() end )

1 Like