Fix the use of queries with a schema in a migration
[akkoma] / priv / repo / migrations / 20190711042024_copy_muted_to_muted_notifications.exs
1 defmodule Pleroma.Repo.Migrations.CopyMutedToMutedNotifications do
2 use Ecto.Migration
3 import Ecto.Query
4 alias Pleroma.User
5
6 def change do
7 query = from(u in "users", where: fragment("not (?->'deactivated' @> 'true')", u.info), select: %{info: u.info}, where: u.local == true, order_by: u.id)
8 Pleroma.Repo.stream(query)
9 |> Enum.each(fn
10 %{info: %{mutes: mutes} = info} = user ->
11 info_cng =
12 Ecto.Changeset.cast(info, %{muted_notifications: mutes}, [:muted_notifications])
13
14 Ecto.Changeset.change(user)
15 |> Ecto.Changeset.put_embed(:info, info_cng)
16 |> Pleroma.Repo.update()
17 end)
18 end
19 end