Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions lib/ecto/adapters/myxql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -416,16 +416,18 @@ defmodule Ecto.Adapters.MyXQL do
def structure_load(default, config) do
path = config[:dump_path] || Path.join(default, "structure.sql")

args = [
"--execute",
"SET FOREIGN_KEY_CHECKS = 0; SOURCE #{path}; SET FOREIGN_KEY_CHECKS = 1",
"--database",
config[:database]
]

case run_with_cmd("mysql", config, args) do
{_output, 0} -> {:ok, path}
{output, _} -> {:error, output}
with {:ok, contents} <- File.read(path) do

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will downstream be able to handle {:error, atom()}?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, yes it handles it:

$ mix ecto.load
** (Mix) The structure for Dummy.Repo couldn't be loaded: :enoent

however previously it was a slightly better error message:

** (Mix) The structure for Dummy.Repo couldn't be loaded: ERROR at line 1: Failed to open file '/Users/wojtek/dummy/priv/repo/structure.sql', error: 2

I will do something like:

      {:error, reason} ->
        {:error, "could not read #{inspect(path)}: #{:file.format_error(reason)}"}

so that we have:

** (Mix) The structure for Dummy.Repo couldn't be loaded: could not read "/Users/wojtek/dummy/priv/repo/structure.sql": no such file or directory

args = [
"--execute",
"SET FOREIGN_KEY_CHECKS = 0; " <> contents <> "; SET FOREIGN_KEY_CHECKS = 1",
"--database",
config[:database]
]

case run_with_cmd("mysql", config, args) do
{_output, 0} -> {:ok, path}
{output, _} -> {:error, output}
end
end
end

Expand Down
Loading