logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

20191029101340_migrate_missing_follow_requests.exs (1110B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Repo.Migrations.MigrateMissingFollowingRelationships do
  5. use Ecto.Migration
  6. def change do
  7. execute(import_pending_follows_from_activities(), "")
  8. end
  9. defp import_pending_follows_from_activities do
  10. """
  11. INSERT INTO
  12. following_relationships (
  13. follower_id,
  14. following_id,
  15. state,
  16. inserted_at,
  17. updated_at
  18. )
  19. SELECT
  20. followers.id,
  21. following.id,
  22. activities.data ->> 'state',
  23. (activities.data ->> 'published') :: timestamp,
  24. now()
  25. FROM
  26. activities
  27. JOIN users AS followers ON (activities.actor = followers.ap_id)
  28. JOIN users AS following ON (activities.data ->> 'object' = following.ap_id)
  29. WHERE
  30. activities.data ->> 'type' = 'Follow'
  31. AND activities.data ->> 'state' = 'pending'
  32. ORDER BY activities.updated_at DESC
  33. ON CONFLICT DO NOTHING
  34. """
  35. end
  36. end