cannery/lib/cannery/repo/migrator.ex

19 lines
349 B
Elixir
Raw Normal View History

2021-09-04 16:14:51 -04:00
defmodule Cannery.Repo.Migrator do
use GenServer
require Logger
2022-01-22 17:21:10 -05:00
2021-09-04 16:14:51 -04:00
def start_link(_) do
GenServer.start_link(__MODULE__, [], [])
end
2022-01-22 17:21:10 -05:00
2021-09-04 16:14:51 -04:00
def init(_) do
migrate!()
{:ok, nil}
end
2022-01-22 17:21:10 -05:00
2021-09-04 16:14:51 -04:00
def migrate! do
path = Application.app_dir(:cannery, "priv/repo/migrations")
Ecto.Migrator.run(Cannery.Repo, path, :up, all: true)
end
2022-01-22 17:21:10 -05:00
end