copy subscriptions on merge instead of moving

This commit is contained in:
byte[] 2020-09-07 19:35:19 -04:00
parent a079eac912
commit ea0c9a8650

View file

@ -731,9 +731,15 @@ defmodule Philomena.Images do
end end
def migrate_subscriptions(source, target) do def migrate_subscriptions(source, target) do
Subscription subscriptions =
|> where(image_id: ^source.id) Subscription
|> Repo.update_all(set: [image_id: target.id]) |> 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 end
def clear_notification(_image, nil), do: nil def clear_notification(_image, nil), do: nil