From 0ad89762a1cfdbb953a12e0434153a5e577f183a Mon Sep 17 00:00:00 2001
From: rinpatch <rinpatch@sdf.org>
Date: Sat, 9 May 2020 18:51:20 +0300
Subject: [PATCH] insert skeletons migration: fix for non-local locals

Apparently some instances have local users with local ap_ids
that are marked as local: false. Needs more investigation into how
that happened.

In the meantime, the skeleton migration was patched to just ignore
all known ap ids, not just locals. Doesn't seem to slow down the migration
too much on patch.cx

Closes #1746
---
 CHANGELOG.md                                                    | 1 +
 .../20200428221338_insert_skeletons_for_deleted_users.exs       | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index d469793f0..4b7fb603d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -44,6 +44,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 
 ### Fixed
 - Healthcheck reporting the number of memory currently used, rather than allocated in total
+- `InsertSkeletonsForDeletedUsers` failing on some instances 
 
 ## [2.0.3] - 2020-05-02
 
diff --git a/priv/repo/migrations/20200428221338_insert_skeletons_for_deleted_users.exs b/priv/repo/migrations/20200428221338_insert_skeletons_for_deleted_users.exs
index 11d9a70ba..2adc38186 100644
--- a/priv/repo/migrations/20200428221338_insert_skeletons_for_deleted_users.exs
+++ b/priv/repo/migrations/20200428221338_insert_skeletons_for_deleted_users.exs
@@ -30,7 +30,7 @@ def change do
           Repo,
           "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 where local = true))) nonexistent_locals;",
+          }/users/[A-Za-z0-9]*' and not(recipient in (select ap_id from users))) nonexistent_locals;",
           [],
           timeout: :infinity
         )