Add option to modify HTTP pool size
[akkoma] / priv / repo / migrations / 20191128153944_fix_missing_following_count.exs
1 defmodule Pleroma.Repo.Migrations.FixMissingFollowingCount do
2 use Ecto.Migration
3
4 def up do
5 """
6 UPDATE
7 users
8 SET
9 following_count = sub.count
10 FROM
11 (
12 SELECT
13 users.id AS sub_id
14 ,COUNT (following_relationships.id)
15 FROM
16 following_relationships
17 ,users
18 WHERE
19 users.id = following_relationships.follower_id
20 AND following_relationships.state = 'accept'
21 GROUP BY
22 users.id
23 ) AS sub
24 WHERE
25 users.id = sub.sub_id
26 AND users.local = TRUE
27 ;
28 """
29 |> execute()
30
31 """
32 UPDATE
33 users
34 SET
35 following_count = 0
36 WHERE
37 following_count IS NULL
38 """
39 |> execute()
40
41 execute("ALTER TABLE users
42 ALTER COLUMN following_count SET DEFAULT 0,
43 ALTER COLUMN following_count SET NOT NULL
44 ")
45 end
46
47 def down do
48 execute("ALTER TABLE users
49 ALTER COLUMN following_count DROP DEFAULT,
50 ALTER COLUMN following_count DROP NOT NULL
51 ")
52 end
53 end