Search code examples
elixirelixir-mix

How to alias run twice in mix.exs?


I'm trying to run two different scripts, v1_to_v2_migrator.exs and update_images.exs

defp aliases do
  ["ecto.reset": ["ecto.drop", "ecto.create", "ecto.migrate", "run priv/repo/v1_to_v2_migrator.exs", "run priv/repo/update_images.exs"]

Only the first file runs. I've tried to reenable run but I can't escape the filename.

"run 'priv/repo/v1_to_v2_migrator.exs'; run -e 'Mix.Task.reenable(:run)'"

gives this error:

** (Mix) No such file: priv/repo/v1_to_v2_migrator.exs;

Where the file ending includes the semicolon.


Solution

  • For your particular example, you can pass multiple files to run:

    mix run -r priv/repo/foo.exs -r priv/repo/bar.exs
    

    But if the question is how to generally reenable tasks, then @Dogbert's and @mudasobwa's approaches are correct.