Commit d7b40dd4 authored by rinpatch's avatar rinpatch

Merge branch 'bugfix/1447-set-following' into 'develop'

Migrations: Set users.following_count to NOT NULL

Closes #1447

See merge request !2021
parents ca1acfa3 f0bdbe3f
Pipeline #20545 failed with stages
in 3 minutes and 43 seconds
defmodule Pleroma.Repo.Migrations.FixMissingFollowingCount do
use Ecto.Migration
def up do
"""
UPDATE
users
SET
following_count = sub.count
FROM
(
SELECT
users.id AS sub_id
,COUNT (following_relationships.id)
FROM
following_relationships
,users
WHERE
users.id = following_relationships.follower_id
AND following_relationships.state = 'accept'
GROUP BY
users.id
) AS sub
WHERE
users.id = sub.sub_id
AND users.local = TRUE
;
"""
|> execute()
"""
UPDATE
users
SET
following_count = 0
WHERE
following_count IS NULL
"""
|> execute()
execute("ALTER TABLE users
ALTER COLUMN following_count SET DEFAULT 0,
ALTER COLUMN following_count SET NOT NULL
")
end
def down do
execute("ALTER TABLE users
ALTER COLUMN following_count DROP DEFAULT,
ALTER COLUMN following_count DROP NOT NULL
")
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment