From 380dd87fa3ec203eec0e635c750bd1f7ecee67d9 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 11 Jul 2019 11:14:41 +0300 Subject: [PATCH] do not override existing market records --- apps/explorer/lib/explorer/market/market.ex | 2 +- apps/explorer/test/explorer/market/market_test.exs | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) 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