1 defmodule Pleroma.Repo.Migrations.InsertSkeletonsForDeletedUsers do
10 Application.ensure_all_started(:flake_id)
13 User.Query.build(%{local: true})
14 |> select([u], u.ap_id)
18 unless local_ap_id == nil do
19 # Hack to get instance base url because getting it from Phoenix
20 # would require starting the whole application
24 |> Map.put(:query, nil)
25 |> Map.put(:path, nil)
28 {:ok, %{rows: ap_ids}} =
29 Ecto.Adapters.SQL.query(
31 "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;",
37 |> Enum.each(fn [ap_id] ->
38 Ecto.Changeset.change(%User{}, deactivated: true, ap_id: ap_id)