From ea0c9a86509be5ca5a583f859388e442c6f178ad Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Mon, 7 Sep 2020 19:35:19 -0400 Subject: [PATCH] copy subscriptions on merge instead of moving --- lib/philomena/images.ex | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/philomena/images.ex b/lib/philomena/images.ex index 1df4d680..313ab59f 100644 --- a/lib/philomena/images.ex +++ b/lib/philomena/images.ex @@ -731,9 +731,15 @@ defmodule Philomena.Images do end def migrate_subscriptions(source, target) do - Subscription - |> where(image_id: ^source.id) - |> Repo.update_all(set: [image_id: target.id]) + subscriptions = + Subscription + |> where(image_id: ^source.id) + |> select([s], %{image_id: type(^target.id, :integer), user_id: s.user_id}) + |> Repo.all() + + {count, nil} = Repo.insert_all(Subscription, subscriptions, on_conflict: :nothing) + + {:ok, count} end def clear_notification(_image, nil), do: nil