1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 # Fix legacy tags set by AdminFE that don't align with TagPolicy MRF
7 defmodule Pleroma.Repo.Migrations.FixLegacyTags do
14 "force_nsfw" => "mrf_tag:media-force-nsfw",
15 "strip_media" => "mrf_tag:media-strip",
16 "force_unlisted" => "mrf_tag:force-unlisted",
17 "sandbox" => "mrf_tag:sandbox",
18 "disable_remote_subscription" => "mrf_tag:disable-remote-subscription",
19 "disable_any_subscription" => "mrf_tag:disable-any-subscription"
23 legacy_tags = Map.keys(@old_new_map)
26 where: fragment("? && ?", u.tags, ^legacy_tags),
27 select: struct(u, [:tags, :id])
29 |> Repo.chunk_stream(100)
30 |> Enum.each(fn user ->
31 fix_tags_changeset(user)
36 defp fix_tags_changeset(%User{tags: tags} = user) do
38 Enum.map(tags, fn tag ->
39 Map.get(@old_new_map, tag, tag)
42 Ecto.Changeset.change(user, tags: new_tags)