/
ecto.drop.ex
46 lines (35 loc) · 1.16 KB
/
ecto.drop.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
defmodule Mix.Tasks.Ecto.Drop do
use Mix.Task
import Mix.Ecto
@shortdoc "Drop the storage for the repo"
@moduledoc """
Drop the storage for the repository.
## Examples
mix ecto.drop
mix ecto.drop -r Custom.Repo
## Command line options
* `-r`, `--repo` - the repo to drop (defaults to `YourApp.Repo`)
* `--no-start` - do not start applications
"""
@doc false
def run(args) do
Mix.Task.run "app.start", args
repo = parse_repo(args)
ensure_repo(repo)
ensure_implements(repo.__adapter__, Ecto.Adapter.Storage,
"to drop storage for #{inspect repo}")
{opts, _, _} = OptionParser.parse args, switches: [quiet: :boolean]
case Ecto.Storage.down(repo) do
:ok ->
unless opts[:quiet] do
Mix.shell.info "The database for #{inspect repo} has been dropped."
end
{:error, :already_down} ->
unless opts[:quiet] do
Mix.shell.info "The database for #{inspect repo} has already been dropped."
end
{:error, term} ->
Mix.raise "The database for #{inspect repo} couldn't be dropped, reason given: #{inspect term}."
end
end
end