From f54f4d0afd79b72c5f98daf84856176140602b23 Mon Sep 17 00:00:00 2001 From: Adhityaa Chandrasekar Date: Sun, 23 Sep 2018 00:47:38 -0400 Subject: [PATCH] db: build the comments count column --- db/20180923004309-comment-count-build.sql | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 db/20180923004309-comment-count-build.sql diff --git a/db/20180923004309-comment-count-build.sql b/db/20180923004309-comment-count-build.sql new file mode 100644 index 0000000..8c826e2 --- /dev/null +++ b/db/20180923004309-comment-count-build.sql @@ -0,0 +1,10 @@ +-- Build the comments count column + +UPDATE pages +SET commentCount = subquery.commentCount +FROM ( + SELECT COUNT(commentHex) as commentCount + FROM comments + WHERE state = 'approved' + GROUP BY (domain, path) +) as subquery;