Note that if these seeds are not for development only, and do things like populate lookup tables that are always necessary, you should tweak the above suggestion a little.
Write the seeding logic as a normal Elixir module and call that from any Mix tasks you might create. I suggest this because the preferred approach to deploying Elixir apps is to use releases, which remove your access to Mix commands.
If the Mix task is very thin and only calls a standard module and its functions, you’ll have less hurdles to continue forward with. When it comes time to deploy the code and run those seeds, you’ll still be able to do so without Mix.
Separately, I’d also suggest either not using Ecto schemas or context modules in your seeds, or making sure to exercise them very regularly. It’s a good candidate for CI if you get that going. Using changesets and schemas in your seeds are more brittle than doing schema-less inserts because the schemas and validations tend to evolve over time, with different requirements, while seeds are not often maintained alongside those changes. You might find a few weeks or months later that your schema logic no longer generates valid rows to insert, and not everyone thinks to wrap them in a database transaction to catch that.






















