-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathcreate.ex
55 lines (41 loc) · 1.28 KB
/
create.ex
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
defmodule EventStore.Tasks.Create do
@moduledoc """
Task to create the EventStore
"""
import EventStore.Tasks.Output
alias EventStore.Storage.Database
alias EventStore.Storage.Schema
@doc """
Runs database and schema create task.
## Parameters
- config: the parsed EventStore config
## Opts
- is_mix: set to `true` if running as part of a Mix task
- quiet: set to `true` to silence output
"""
def exec(config, opts \\ []) do
opts = Keyword.merge([is_mix: false, quiet: false], opts)
case Database.create(config) do
:ok ->
write_info("The EventStore database has been created.", opts)
{:error, :already_up} ->
write_info("The EventStore database already exists.", opts)
{:error, term} ->
raise_msg(
"The EventStore database couldn't be created, reason given: #{inspect(term)}.",
opts
)
end
case Schema.create(config) do
:ok ->
write_info("The EventStore schema has been created.", opts)
{:error, :already_up} ->
write_info("The EventStore schema already exists.", opts)
{:error, term} ->
raise_msg(
"The EventStore schema couldn't be created, reason given: #{inspect(term)}.",
opts
)
end
end
end