summaryrefslogtreecommitdiff
path: root/priv/repo/migrations/20190711042024_copy_muted_to_muted_notifications.exs
blob: 50669902e57956be76b075c82b0d771bc6316152 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
defmodule Pleroma.Repo.Migrations.CopyMutedToMutedNotifications do
  use Ecto.Migration
  alias Pleroma.User

  def change do
    query =
      User.Query.build(%{
        local: true,
        active: true,
        order_by: :id
      })

    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