pleroma/priv/repo/migrations/20191029101340_migrate_missing_follow_requests.exs

40 lines
1.1 KiB
Elixir
Raw Normal View History

2022-02-25 22:11:42 -08:00
# Pleroma: A lightweight social networking server
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
2022-02-25 22:11:42 -08:00
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Repo.Migrations.MigrateMissingFollowingRelationships do
2019-10-29 03:16:34 -07:00
use Ecto.Migration
def change do
execute(import_pending_follows_from_activities(), "")
end
defp import_pending_follows_from_activities do
"""
INSERT INTO
following_relationships (
follower_id,
following_id,
state,
inserted_at,
updated_at
)
SELECT
followers.id,
following.id,
activities.data ->> 'state',
(activities.data ->> 'published') :: timestamp,
now()
FROM
activities
JOIN users AS followers ON (activities.actor = followers.ap_id)
JOIN users AS following ON (activities.data ->> 'object' = following.ap_id)
WHERE
activities.data ->> 'type' = 'Follow'
AND activities.data ->> 'state' = 'pending'
ORDER BY activities.updated_at DESC
ON CONFLICT DO NOTHING
"""
end
end