diff --git a/apps/explorer/lib/explorer/market/market.ex b/apps/explorer/lib/explorer/market/market.ex index a9be83a5c8..3adb7316fd 100644 --- a/apps/explorer/lib/explorer/market/market.ex +++ b/apps/explorer/lib/explorer/market/market.ex @@ -45,7 +45,7 @@ defmodule Explorer.Market do Decimal.equal?(item.closing_price, 0) && Decimal.equal?(item.opening_price, 0) end) - Repo.insert_all(MarketHistory, records_without_zeroes, on_conflict: :replace_all, conflict_target: [:date]) + Repo.insert_all(MarketHistory, records_without_zeroes, on_conflict: :nothing, conflict_target: [:date]) end def add_price(%{symbol: symbol} = token) do diff --git a/apps/explorer/test/explorer/market/market_test.exs b/apps/explorer/test/explorer/market/market_test.exs index d0020017d2..881e1dccc8 100644 --- a/apps/explorer/test/explorer/market/market_test.exs +++ b/apps/explorer/test/explorer/market/market_test.exs @@ -91,9 +91,11 @@ defmodule Explorer.MarketTest do assert fetched_record.opening_price == old_record.opening_price end - test "overrides existing records on date conflict" do + test "does not override existing records on date conflict" do date = ~D[2018-04-01] - Repo.insert(%MarketHistory{date: date}) + + {:ok, old_record} = + Repo.insert(%MarketHistory{date: date, closing_price: Decimal.new(2), opening_price: Decimal.new(2)}) new_record = %{ date: date, @@ -104,8 +106,8 @@ defmodule Explorer.MarketTest do Market.bulk_insert_history([new_record]) fetched_record = Repo.get_by(MarketHistory, date: date) - assert fetched_record.closing_price == new_record.closing_price - assert fetched_record.opening_price == new_record.opening_price + assert fetched_record.closing_price == old_record.closing_price + assert fetched_record.opening_price == old_record.opening_price end end end