~ihabunek/triglav

ref: 1c7461f07a0ceea83e7bf60e10c9de3e3de344ba triglav/lib/triglav/release.ex -rw-r--r-- 987 bytes
1c7461f0Ivan Habunek Make rollback in releases work on all repos 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
defmodule Triglav.Release do
  @app :triglav

  def migrate do
    load_app()

    for repo <- repos() do
      {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true))
    end
  end

  def rollback(version) do
    load_app()

    for repo <- repos() do
      {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version))
    end
  end

  def import_zet(opts \\ []) do
    load_app()
    Mix.Tasks.Triglav.ImportZet.run(opts)
  end

  def osmosis_init() do
    load_app()
    Mix.Tasks.Triglav.OsmosisInit.run([])
  end

  def osmosis_load(pbf_path) do
    load_app()
    Mix.Tasks.Triglav.OsmosisLoad.run([pbf_path])
  end

  def osmosis_update() do
    load_app()
    Mix.Tasks.Triglav.OsmosisUpdate.run([])
  end

  def validate_routes do
    load_app()
    Mix.Tasks.Triglav.ValidateRoutes.run([])
  end

  defp repos do
    Application.fetch_env!(@app, :ecto_repos)
  end

  defp load_app do
    Application.load(@app)
  end
end