> mix new demo --sup
The --sup
flag tells mix to stub out an application process. We'll use this later to start our
Ecto repo.
defp deps do
[
{:ecto, "~> 2.0"},
{:postgrex, "~> 0.11"}
]
end
> mix deps.get
> mix ecto.gen.repo -r Demo.Repo
Add the Repo supervisor to ./lib/demo/application.ex
def start(_type, _args) do
children = [
Demo.Repo,
]
...
end
Update the repo config in ./config/config.exs
config :demo, Demo.Repo,
adapter: Ecto.Adapters.Postgres,
database: "demo_dev",
username: "postgres",
password: "postgres",
hostname: "localhost"
config :demo, ecto_repos: [Demo.Repo]
> mix ecto.create
Heads Up! If you get an error here, run psql postgres -c "CREATE ROLE postgres LOGIN CREATEDB;"
> mix ecto.gen.migration create_albums