Elixir - Mix Aliases to simplify your Ecto workflow

There are some cases where you run a sequence of mix tasks one after another.

Here’s an example:

mix ecto.create
mix ecto.migrate
mix run priv/repo/seeds.exs

The above commands create the database, run all your migrations and load the fixtures for you respectively.

Wouldn’t it be easier to just run one command and in turn that wraps all the three mix tasks into a single command?

Enter mix Aliases.

from the official docs:

Aliases are shortcuts or tasks specific to the current project. to define one edit your mix.exs

defmodule MyApp.MixProject do
  use Mix.Project

  def project do
    [
      app: :my_app,
      version: "1.0.0",
      aliases: aliases()
    ]
  end

  defp aliases do
    [
      "ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
      "ecto.reset": ["ecto.drop", "ecto.setup"]
    ]
  end

end

Now you can just run mix ecto.reset to reset your database and run mix ecto.setup to run migrations and load the sample fixtures.