-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.ex
More file actions
82 lines (66 loc) · 1.62 KB
/
Copy pathrelease.ex
File metadata and controls
82 lines (66 loc) · 1.62 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
defmodule Parceroo.Release do
@moduledoc """
Module containing release commands that can be used in production
Since we don't have Mix, a build tool, inside releases, which are a production
artifact, we need to bring said commands directly into the release.
"""
@app :parseroo
alias Ecto.Migrator
@doc """
Run application migrations
Usage: $_build/prod/rel/parseroo/bin/parseroo eval "Parceroo.Release.migrate"
"""
def migrate do
load_app()
for repo <- repos() do
{:ok, _, _} =
Migrator.with_repo(
repo,
&Migrator.run(&1, :up, all: true)
)
end
end
@doc """
Do rollback into application migrations
Usage: $_build/prod/rel/parseroo/bin/parseroo eval "Parceroo.Release.rollback"
"""
def rollback(repo, version) do
load_app()
{:ok, _, _} =
Migrator.with_repo(
repo,
&Migrator.run(
&1,
:down,
to: version
)
)
end
@doc """
Run application seeds
Usage: $_build/prod/rel/parseroo/bin/parseroo eval "Parceroo.Release.seed"
"""
def seed do
load_app()
Enum.each(repos(), fn repo ->
{:ok, _, _} = Migrator.with_repo(repo, &run_seeds_for/1)
end)
end
defp run_seeds_for(repo) do
seed_script = seeds_path(repo)
if File.exists?(seed_script) do
Code.eval_file(seed_script)
end
end
defp seeds_path(repo) do
repo.config()
|> Keyword.fetch!(:otp_app)
|> Application.app_dir("priv/repo/seeds.exs")
end
defp repos do
Application.fetch_env!(@app, :ecto_repos)
end
defp load_app do
Application.load(@app)
end
end