Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions integration_test/myxql/storage_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,20 @@ defmodule Ecto.Integration.StorageTest do
drop_database()
end

test "structure load will fail on SQL errors" do
create_database()
File.mkdir_p!(tmp_path())
error_path = Path.join(tmp_path(), "error.sql")
File.write!(error_path, "SELECT 1; SELECKT 1; SELECT 2;")

{:error, message} =
Ecto.Adapters.MyXQL.structure_load(tmp_path(), [dump_path: error_path] ++ params())

assert message =~ ~r/ERROR.*SELECKT/
after
drop_database()
end

test "storage status is up when database is created" do
create_database()
assert :up == Ecto.Adapters.MyXQL.storage_status(params())
Expand Down
9 changes: 8 additions & 1 deletion lib/ecto/adapters/myxql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -588,12 +588,16 @@ defmodule Ecto.Adapters.MyXQL do
args: args
]

# Trap exits in case mysql dies in the middle of execution so that we can surface the error
old_trap_exit = Process.flag(:trap_exit, true)
port = Port.open({:spawn_executable, abs_cmd}, port_opts)
Port.command(port, contents)
# Use this as a signal to close the port since we cannot
# send an exit command to mysql in batch mode
Port.command(port, ";SELECT '__ECTO_EOF__';\n")
collect_output(port, "")
result = collect_output(port, "")
Process.flag(:trap_exit, old_trap_exit)
result
end

defp args_env(opts, opt_args) do
Expand Down Expand Up @@ -653,6 +657,9 @@ defmodule Ecto.Adapters.MyXQL do
collect_output(port, acc)
end

{:EXIT, ^port, _reason} ->
{acc, 1}

{^port, {:exit_status, status}} ->
{acc, status}
end
Expand Down
Loading