Packages
ecto_sql
3.2.1
3.14.0
3.13.5
3.13.4
3.13.3
3.13.2
3.13.1
3.13.0
3.12.1
3.12.0
3.11.3
3.11.2
3.11.1
3.11.0
3.10.2
3.10.1
3.10.0
3.9.2
3.9.1
3.9.0
3.8.3
3.8.2
3.8.1
3.8.0
3.7.2
3.7.1
3.7.0
3.6.2
3.6.1
3.6.0
3.5.4
3.5.3
3.5.2
3.5.1
3.5.0
3.5.0-rc.1
3.5.0-rc.0
3.4.5
3.4.4
3.4.3
3.4.2
3.4.1
3.4.0
3.3.4
3.3.3
3.3.2
3.3.1
3.3.0
3.2.2
3.2.1
3.2.0
3.1.6
3.1.5
3.1.4
3.1.3
3.1.2
3.1.1
3.1.0
3.0.5
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
3.0.0-rc.1
3.0.0-rc.0
SQL-based adapters for Ecto and database migrations
Current section
Files
Jump to
Current section
Files
lib/mix/tasks/ecto.dump.ex
defmodule Mix.Tasks.Ecto.Dump do
use Mix.Task
import Mix.Ecto
import Mix.EctoSQL
@shortdoc "Dumps the repository database structure"
@default_opts [quiet: false]
@aliases [
d: :dump_path,
q: :quiet,
r: :repo
]
@switches [
dump_path: :string,
quiet: :boolean,
repo: [:string, :keep],
no_compile: :boolean,
no_deps_check: :boolean
]
@moduledoc """
Dumps the current environment's database structure for the
given repository into a structure file.
The repository must be set under `:ecto_repos` in the
current app configuration or given via the `-r` option.
This task needs some shell utility to be present on the machine
running the task.
Database | Utility needed
:--------- | :-------------
PostgreSQL | pg_dump
MySQL | mysqldump
## Example
mix ecto.dump
## Command line options
* `-r`, `--repo` - the repo to load the structure info from
* `-d`, `--dump-path` - the path of the dump file to create
* `-q`, `--quiet` - run the command quietly
* `--no-compile` - does not compile applications before dumping
* `--no-deps-check` - does not check depedendencies before dumping
"""
@impl true
def run(args) do
{opts, _} = OptionParser.parse! args, strict: @switches, aliases: @aliases
opts = Keyword.merge(@default_opts, opts)
Enum.each parse_repo(args), fn repo ->
ensure_repo(repo, args)
ensure_implements(repo.__adapter__, Ecto.Adapter.Structure,
"dump structure for #{inspect repo}")
config = Keyword.merge(repo.config, opts)
case repo.__adapter__.structure_dump(source_repo_priv(repo), config) do
{:ok, location} ->
unless opts[:quiet] do
Mix.shell.info "The structure for #{inspect repo} has been dumped to #{location}"
end
{:error, term} when is_binary(term) ->
Mix.raise "The structure for #{inspect repo} couldn't be dumped: #{term}"
{:error, term} ->
Mix.raise "The structure for #{inspect repo} couldn't be dumped: #{inspect term}"
end
end
end
end