Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
951B

  1. defmodule Pleroma.Repo.Migrations.MigrateMissingFollowingRelationships do
  2. use Ecto.Migration
  3. def change do
  4. execute(import_pending_follows_from_activities(), "")
  5. end
  6. defp import_pending_follows_from_activities do
  7. """
  8. INSERT INTO
  9. following_relationships (
  10. follower_id,
  11. following_id,
  12. state,
  13. inserted_at,
  14. updated_at
  15. )
  16. SELECT
  17. followers.id,
  18. following.id,
  19. activities.data ->> 'state',
  20. (activities.data ->> 'published') :: timestamp,
  21. now()
  22. FROM
  23. activities
  24. JOIN users AS followers ON (activities.actor = followers.ap_id)
  25. JOIN users AS following ON (activities.data ->> 'object' = following.ap_id)
  26. WHERE
  27. activities.data ->> 'type' = 'Follow'
  28. AND activities.data ->> 'state' = 'pending'
  29. ORDER BY activities.updated_at DESC
  30. ON CONFLICT DO NOTHING
  31. """
  32. end
  33. end