fediverse.space/backend/lib/backend/release.ex

37 wiersze
850 B
Elixir
Czysty Zwykły widok Historia

2019-07-14 11:47:06 +00:00
defmodule Backend.Release do
@app :backend
2019-07-26 22:30:11 +00:00
alias Elasticsearch.Index
alias Backend.Elasticsearch.Cluster
def run_all do
migrate()
index()
end
2019-07-14 11:47:06 +00:00
def migrate do
for repo <- repos() do
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
end
end
2019-07-26 22:30:11 +00:00
def index do
2019-07-27 10:13:42 +00:00
# TODO: this isn't the right way to handle this.
# See https://github.com/danielberkompas/elasticsearch-elixir/issues/76
Application.ensure_all_started(@app)
2019-07-31 15:56:21 +00:00
IO.puts("Indexing...")
2019-07-26 22:30:11 +00:00
Index.hot_swap(Cluster, "instances")
2019-07-31 15:56:21 +00:00
IO.puts("Done indexing.")
2019-07-27 10:13:42 +00:00
:init.stop()
2019-07-26 22:30:11 +00:00
end
2019-07-14 11:47:06 +00:00
def rollback(repo, version) do
{:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
end
defp repos do
Application.load(@app)
Application.fetch_env!(@app, :ecto_repos)
end
end