2019-07-14 07:29:31 -06:00
|
|
|
defmodule Pleroma.Repo.Migrations.CopyMutedToMutedNotifications do
|
|
|
|
use Ecto.Migration
|
2019-10-06 08:05:51 -06:00
|
|
|
import Ecto.Query
|
2019-07-14 07:29:31 -06:00
|
|
|
alias Pleroma.User
|
|
|
|
|
|
|
|
def change do
|
2019-10-06 08:05:51 -06:00
|
|
|
query = from(u in "users", where: fragment("not (?->'deactivated' @> 'true')", u.info), select: %{info: u.info}, where: u.local == true, order_by: u.id)
|
2019-07-14 07:29:31 -06:00
|
|
|
Pleroma.Repo.stream(query)
|
|
|
|
|> Enum.each(fn
|
|
|
|
%{info: %{mutes: mutes} = info} = user ->
|
|
|
|
info_cng =
|
|
|
|
Ecto.Changeset.cast(info, %{muted_notifications: mutes}, [:muted_notifications])
|
|
|
|
|
|
|
|
Ecto.Changeset.change(user)
|
|
|
|
|> Ecto.Changeset.put_embed(:info, info_cng)
|
|
|
|
|> Pleroma.Repo.update()
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|