2022-07-25 19:31:54 -04:00
|
|
|
defmodule Memex.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
|
|
|
|
|
|
|
|
def start_link(_) do
|
|
|
|
GenServer.start_link(__MODULE__, [], [])
|
|
|
|
end
|
|
|
|
|
|
|
|
def init(_) do
|
|
|
|
migrate!()
|
|
|
|
{:ok, nil}
|
|
|
|
end
|
|
|
|
|
|
|
|
def migrate! do
|
2022-07-25 19:31:54 -04:00
|
|
|
path = Application.app_dir(:memex, "priv/repo/migrations")
|
|
|
|
Ecto.Migrator.run(Memex.Repo, path, :up, all: true)
|
2021-09-04 16:19:23 -04:00
|
|
|
end
|
|
|
|
end
|