1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Repo.Migrations.FixMissingFollowingCount do
13 following_count = sub.count
18 ,COUNT (following_relationships.id)
20 following_relationships
23 users.id = following_relationships.follower_id
24 AND following_relationships.state = 'accept'
30 AND users.local = TRUE
41 following_count IS NULL
45 execute("ALTER TABLE users
46 ALTER COLUMN following_count SET DEFAULT 0,
47 ALTER COLUMN following_count SET NOT NULL
52 execute("ALTER TABLE users
53 ALTER COLUMN following_count DROP DEFAULT,
54 ALTER COLUMN following_count DROP NOT NULL