How to run seeds.exs for Elixir/Phoenix App?

Hello!

Yes, the seeds aren’t auto-run. That’s a general situation with Elixir releases. Typically, you only want them run once. I like to write my seeds so they can be run multiple times (ie idempotent). However, it’s unique to each project and that means the solution is as well.

What I do is put the seeds into a regular module like MyApp.GlobalSetup. Then define a function like seed/0 or populate_pick_list_options or whatever.

Then SSH into an instance and run it in an IEx shell. Ex: MyApp.GlobalSetup.seed.

I hope that helps!

10 Likes