cannery/lib/cannery/repo/migrator.ex

23 lines
437 B
Elixir
Raw Normal View History

2021-09-04 16:14:51 -04:00
defmodule Cannery.Repo.Migrator do
2022-01-22 21:40:29 -05:00
@moduledoc """
Genserver to automatically run migrations in prod env
"""
2021-09-04 16:14:51 -04:00
use GenServer
require Logger
2022-01-22 17:21:10 -05:00
2022-03-28 23:05:12 -04:00
def start_link(_opts) do
2021-09-04 16:14:51 -04:00
GenServer.start_link(__MODULE__, [], [])
end
2022-01-22 17:21:10 -05:00
2022-03-28 23:05:12 -04:00
def init(_opts) do
2021-09-04 16:14:51 -04:00
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