2 ADD COLUMN deleted boolean DEFAULT FALSE NOT NULL;
5 ADD COLUMN deleted boolean DEFAULT FALSE NOT NULL;
8 ADD COLUMN deleted boolean DEFAULT FALSE NOT NULL;
11 DROP VIEW community_view;
13 CREATE VIEW community_view AS
14 with all_community AS (
23 c.creator_id = u.id) AS creator_name,
30 c.category_id = ct.id) AS category_name,
37 cf.community_id = c.id) AS number_of_subscribers,
44 p.community_id = c.id) AS number_of_posts,
53 AND p.id = co.post_id) AS number_of_comments
67 AND ac.id = cf.community_id) AS subscribed
70 CROSS JOIN all_community ac
81 CREATE VIEW post_view AS
91 p.creator_id = user_.id) AS creator_name,
98 p.community_id = community.id) AS community_name,
105 p.community_id = c.id) AS community_removed,
112 p.community_id = c.id) AS community_deleted,
119 comment.post_id = p.id) AS number_of_comments,
120 coalesce(sum(pl.score), 0) AS score,
122 CASE WHEN pl.score = 1 THEN
128 CASE WHEN pl.score = - 1 THEN
133 hot_rank (coalesce(sum(pl.score), 0), p.published) AS hot_rank
136 LEFT JOIN post_like pl ON p.id = pl.post_id
143 coalesce(pl.score, 0) AS my_vote,
148 community_follower cf
151 AND cf.community_id = ap.community_id) AS subscribed,
159 AND pr.post_id = ap.id) AS read,
167 AND ps.post_id = ap.id) AS saved
170 CROSS JOIN all_post ap
171 LEFT JOIN post_like pl ON u.id = pl.user_id
172 AND ap.id = pl.post_id
184 DROP VIEW reply_view;
186 DROP VIEW comment_view;
188 CREATE VIEW comment_view AS
189 with all_comment AS (
205 c.creator_id = u.id) AS banned,
210 community_user_ban cb,
213 c.creator_id = cb.user_id
215 AND p.community_id = cb.community_id) AS banned_from_community,
222 c.creator_id = user_.id) AS creator_name,
223 coalesce(sum(cl.score), 0) AS score,
225 CASE WHEN cl.score = 1 THEN
231 CASE WHEN cl.score = - 1 THEN
238 LEFT JOIN comment_like cl ON c.id = cl.comment_id
245 coalesce(cl.score, 0) AS my_vote,
253 AND cs.comment_id = ac.id) AS saved
256 CROSS JOIN all_comment ac
257 LEFT JOIN comment_like cl ON u.id = cl.user_id
258 AND ac.id = cl.comment_id
268 CREATE VIEW reply_view AS
272 c2.creator_id AS sender_id,
273 c.creator_id AS recipient_id
276 INNER JOIN comment c2 ON c.id = c2.parent_id
278 c2.creator_id != c.creator_id
279 -- Do union where post is null
283 c.creator_id AS sender_id,
284 p.creator_id AS recipient_id
290 AND c.parent_id IS NULL
291 AND c.creator_id != p.creator_id
295 closereply.recipient_id
300 closereply.id = cv.id;