/
ecto.drop.ex
36 lines (27 loc) · 970 Bytes
/
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
defmodule Mix.Tasks.Ecto.Drop do
use Mix.Task
import Mix.Ecto
@shortdoc "Drop the database for the repo"
@moduledoc """
Drop the database for the given repository, as specified in the repo's `url`.
## Command line options
* `--no-start` - do not start applications
## Examples
mix ecto.drop MyApp.Repo
"""
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 create storage for #{inspect repo}")
case Ecto.Storage.down(repo) do
:ok ->
Mix.shell.info "The database for repo #{inspect repo} has been dropped."
{:error, :already_down} ->
Mix.shell.info "The database for repo #{inspect repo} has already been dropped."
{:error, term} ->
raise Mix.Error, message:
"The database for repo #{inspect repo} couldn't be dropped, reason given: #{term}."
end
end
end