diff options
author | Dessalines <happydooby@gmail.com> | 2019-04-20 11:17:00 -0700 |
---|---|---|
committer | Dessalines <happydooby@gmail.com> | 2019-04-20 11:17:00 -0700 |
commit | 72798d1cc14bad932c59cd9c21b440f431e02e99 (patch) | |
tree | f3bc26c1f2c1f75bdfcf7b6e5b22f24e93c7a757 /server/migrations | |
parent | 103a92d6b64701967a2eeaccf33d939106f129e1 (diff) |
Mostly working, before merge
Diffstat (limited to 'server/migrations')
-rw-r--r-- | server/migrations/2019-04-03-155309_create_comment_view/down.sql | 1 | ||||
-rw-r--r-- | server/migrations/2019-04-03-155309_create_comment_view/up.sql | 25 |
2 files changed, 26 insertions, 0 deletions
diff --git a/server/migrations/2019-04-03-155309_create_comment_view/down.sql b/server/migrations/2019-04-03-155309_create_comment_view/down.sql index 2da934a4..c19d5ff7 100644 --- a/server/migrations/2019-04-03-155309_create_comment_view/down.sql +++ b/server/migrations/2019-04-03-155309_create_comment_view/down.sql @@ -1 +1,2 @@ +drop view reply_view; drop view comment_view; diff --git a/server/migrations/2019-04-03-155309_create_comment_view/up.sql b/server/migrations/2019-04-03-155309_create_comment_view/up.sql index a78e3ac3..24ce98fc 100644 --- a/server/migrations/2019-04-03-155309_create_comment_view/up.sql +++ b/server/migrations/2019-04-03-155309_create_comment_view/up.sql @@ -33,3 +33,28 @@ select null as saved from all_comment ac ; + +create view reply_view as +with closereply as ( + select + c2.id, + c2.creator_id as sender_id, + c.creator_id as recipient_id + from comment c + inner join comment c2 on c.id = c2.parent_id + where c2.creator_id != c.creator_id + -- Do union where post is null + union + select + c.id, + c.creator_id as sender_id, + p.creator_id as recipient_id + from comment c, post p + where c.post_id = p.id and c.parent_id is null and c.creator_id != p.creator_id +) +select cv.*, +closereply.recipient_id +from comment_view cv, closereply +where closereply.id = cv.id +; + |