memEx/lib/lokal/repo/migrator.ex

23 lines
439 B
Elixir
Raw Normal View History

2021-09-04 16:19:23 -04:00
defmodule Lokal.Repo.Migrator do
2022-01-22 20:44:38 -05:00
@moduledoc """
Genserver to automatically perform all migration on app start
"""
2021-09-04 16:19:23 -04:00
use GenServer
require Logger
2023-02-04 17:28:53 -05:00
def start_link(_opts) do
2021-09-04 16:19:23 -04:00
GenServer.start_link(__MODULE__, [], [])
end
2023-02-04 17:28:53 -05:00
def init(_opts) do
2021-09-04 16:19:23 -04:00
migrate!()
{:ok, nil}
end
def migrate! do
path = Application.app_dir(:lokal, "priv/repo/migrations")
Ecto.Migrator.run(Lokal.Repo, path, :up, all: true)
end
end