Skip to content

Commit 3b08104

Browse files
Suppress query logs in mix ecto.load when quiet flag is given. (#503)
1 parent 366089a commit 3b08104

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/ecto/adapters/sql.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,11 @@ defmodule Ecto.Adapters.SQL do
566566
Returns `true` if the `table` exists in the `repo`, otherwise `false`.
567567
The table is checked against the current database/schema in the connection.
568568
"""
569-
@spec table_exists?(Ecto.Repo.t, table :: String.t) :: boolean
570-
def table_exists?(repo, table) when is_atom(repo) do
569+
@spec table_exists?(Ecto.Repo.t, table :: String.t, opts :: Keyword.t) :: boolean
570+
def table_exists?(repo, table, opts \\ []) when is_atom(repo) do
571571
%{sql: sql} = adapter_meta = Ecto.Adapter.lookup_meta(repo)
572572
{query, params} = sql.table_exists_query(table)
573-
query!(adapter_meta, query, params, []).num_rows != 0
573+
query!(adapter_meta, query, params, opts).num_rows != 0
574574
end
575575

576576
# Returns a formatted table for a given query `result`.

lib/mix/tasks/ecto.load.ex

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,10 @@ defmodule Mix.Tasks.Ecto.Load do
5656
"""
5757

5858
@impl true
59-
def run(args, table_exists? \\ &Ecto.Adapters.SQL.table_exists?/2) do
59+
def run(args, table_exists? \\ &Ecto.Adapters.SQL.table_exists?/3) do
6060
{opts, _} = OptionParser.parse!(args, strict: @switches, aliases: @aliases)
6161
opts = Keyword.merge(@default_opts, opts)
62+
opts = if opts[:quiet], do: Keyword.put(opts, :log, false), else: opts
6263

6364
Enum.each(parse_repo(args), fn repo ->
6465
ensure_repo(repo, args)
@@ -70,7 +71,7 @@ defmodule Mix.Tasks.Ecto.Load do
7071
)
7172

7273
{migration_repo, source} = Ecto.Migration.SchemaMigration.get_repo_and_source(repo, repo.config())
73-
{:ok, loaded?, _} = Ecto.Migrator.with_repo(migration_repo, &table_exists?.(&1, source))
74+
{:ok, loaded?, _} = Ecto.Migrator.with_repo(migration_repo, table_exists_closure(table_exists?, source, opts))
7475

7576
for repo <- Enum.uniq([repo, migration_repo]) do
7677
cond do
@@ -87,6 +88,14 @@ defmodule Mix.Tasks.Ecto.Load do
8788
end)
8889
end
8990

91+
defp table_exists_closure(fun, source, opts) when is_function(fun, 3) do
92+
&fun.(&1, source, opts)
93+
end
94+
95+
defp table_exists_closure(fun, source, _opts) when is_function(fun, 2) do
96+
&fun.(&1, source)
97+
end
98+
9099
defp skip_safety_warnings? do
91100
Mix.Project.config()[:start_permanent] != true
92101
end

0 commit comments

Comments
 (0)