mirror of
https://git.pleroma.social/sjw/pleroma.git
synced 2024-12-23 13:35:04 +01:00
Migrations: Set users.following_count to NOT NULL
Also set following_count for local users to the correct value and for remote users to 0.
This commit is contained in:
parent
98990d2d61
commit
f0bdbe3f61
@ -0,0 +1,53 @@
|
||||
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
|
Loading…
Reference in New Issue
Block a user