How do I run an elixir script from my seeds.exs?

I have an elixir named import_users.exs. If I want to run this script, I would type the following line in my command line.

$ mix run filepath/import_users.exs

How can I run this script from the seeds.exs file? The reason I want to know this is because I simply need to type mix ecto.reset to setup db for running it locally.

Thanks in advance

mix ecto.reset is just an alias defined in your mix.exs. You can define more files than just seeds.exs there.

1 Like

If you don’t want to add another entry to your mix.exs file, you can try using Code.eval_file/2.

1 Like

Thank you @LostKobrakai. You are basically telling me to put a new file under the aliases/0 function in mix.exs. So, in my case it could be like this:

      "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs", "run file.exs"]

Thank you @thiagomajesk. This solution also helps :innocent: