1 defmodule Pleroma.Repo.Migrations.UsersPopulateEmoji do
10 execute("ALTER TABLE users ALTER COLUMN emoji SET DEFAULT '{}'::jsonb")
11 execute("UPDATE users SET emoji = DEFAULT WHERE emoji = '[]'::jsonb")
14 |> select([u], struct(u, [:id, :ap_id, :source_data]))
16 |> Enum.each(fn user ->
21 %{"type" => "Emoji"} -> true
24 |> Enum.reduce(%{}, fn %{"icon" => %{"url" => url}, "name" => name}, acc ->
25 Map.put(acc, String.trim(name, ":"), url)
29 |> Ecto.Changeset.cast(%{emoji: emoji}, [:emoji])
35 execute("ALTER TABLE users ALTER COLUMN emoji SET DEFAULT '[]'::jsonb")
36 execute("UPDATE users SET emoji = DEFAULT WHERE emoji = '{}'::jsonb")