summaryrefslogtreecommitdiff
path: root/priv
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2019-11-29 10:17:59 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2019-11-29 10:17:59 +0300
commit52cc7de82cf3aa637d599edc357909be8c9366eb (patch)
tree3331c84530c0d93c41171f83c6270c8d499f5195 /priv
parentc8d3c3bfeca66d16846f97b50328e0718cfe5fef (diff)
parentd7b40dd4ba5bf3890be8a8b69d5aff84f5ffc5d2 (diff)
downloadpleroma-52cc7de82cf3aa637d599edc357909be8c9366eb.tar.gz
pleroma-52cc7de82cf3aa637d599edc357909be8c9366eb.zip
Merge remote-tracking branch 'remotes/upstream/develop' into 1335-user-api-id-fields-relations
# Conflicts: # mix.lock
Diffstat (limited to 'priv')
-rw-r--r--priv/repo/migrations/20191128153944_fix_missing_following_count.exs53
1 files changed, 53 insertions, 0 deletions
diff --git a/priv/repo/migrations/20191128153944_fix_missing_following_count.exs b/priv/repo/migrations/20191128153944_fix_missing_following_count.exs
new file mode 100644
index 000000000..3236de7a4
--- /dev/null
+++ b/priv/repo/migrations/20191128153944_fix_missing_following_count.exs
@@ -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