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 defmodule Pleroma.Repo.Migrations.InsertSkeletonsForDeletedUsers do
14 Application.ensure_all_started(:flake_id)
17 User.Query.build(%{local: true})
18 |> select([u], u.ap_id)
22 unless local_ap_id == nil do
23 # Hack to get instance base url because getting it from Phoenix
24 # would require starting the whole application
28 |> Map.put(:query, nil)
29 |> Map.put(:path, nil)
32 {:ok, %{rows: ap_ids}} =
33 Ecto.Adapters.SQL.query(
35 "select distinct unnest(nonexistent_locals.recipients) from activities, lateral (select array_agg(recipient) as recipients from unnest(activities.recipients) as recipient where recipient similar to '#{instance_uri}/users/[A-Za-z0-9]*' and not(recipient in (select ap_id from users))) nonexistent_locals;",
41 |> Enum.each(fn [ap_id] ->
42 Ecto.Changeset.change(%User{}, deactivated: true, ap_id: ap_id)