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
- })
+ execute("update users set info = '{}' where info is null")
- 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)
+ execute(
+ "update users set info = safe_jsonb_set(info, '{muted_notifications}', info->'mutes', true) where local = true"
+ )
end
end