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
|
|
|
|
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
|