When deleting a user we also delete any groups that user created that don't contain any annotations by other users. Change this to ignore whether the user created a group and instead delete any groups that the user is the only owner of, again as long as the group doesn't contain any annotations by other users.
With the current version of the code the SQL query that's ultimately generated is:
SELECT "group".id
FROM "group"
LEFT OUTER JOIN annotation ON annotation.groupid = "group".pubid AND annotation.deleted IS false
WHERE "group".id IN (
SELECT user_group.group_id
FROM user_group
WHERE user_group.group_id IN (
SELECT user_group.group_id
FROM user_group
WHERE (user_group.roles @> '"owner"'::jsonb)
GROUP BY user_group.group_id
HAVING count(user_group.group_id) = 1
)
AND (user_group.roles @> '"owner"'::jsonb)
AND user_group.user_id = 22562
)
GROUP BY "group".id
HAVING count(annotation.id) = 0;
It's not currently possible to test that query in production because the roles column hasn't been deployed to production yet.
When deleting a user we also delete any groups that user created that don't contain any annotations by other users. Change this to ignore whether the user created a group and instead delete any groups that the user is the only owner of, again as long as the group doesn't contain any annotations by other users.
With the current version of the code the SQL query that's ultimately generated is:
It's not currently possible to test that query in production because the
roles
column hasn't been deployed to production yet.