diff --git a/lib/ecto/adapters/myxql.ex b/lib/ecto/adapters/myxql.ex index 45ef3fc28..dc595d066 100644 --- a/lib/ecto/adapters/myxql.ex +++ b/lib/ecto/adapters/myxql.ex @@ -416,16 +416,22 @@ 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} + case File.read(path) do + {:ok, contents} -> + 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 + + {:error, reason} -> + {:error, "could not read #{inspect(path)}: #{:file.format_error(reason)}"} end end