From eb9b4d18b80e5b89e9cd2986ed15b7bb07252d96 Mon Sep 17 00:00:00 2001 From: Teemu Patja Date: Wed, 23 Aug 2017 22:12:55 +0300 Subject: [PATCH] Include value_usd and tokens in sql views --- ...220139-usd-value-to-activity-feed.down.sql | 0 ...23220139-usd-value-to-activity-feed.up.sql | 96 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 resources/migrations/20170823220139-usd-value-to-activity-feed.down.sql create mode 100644 resources/migrations/20170823220139-usd-value-to-activity-feed.up.sql diff --git a/resources/migrations/20170823220139-usd-value-to-activity-feed.down.sql b/resources/migrations/20170823220139-usd-value-to-activity-feed.down.sql new file mode 100644 index 0000000..e69de29 diff --git a/resources/migrations/20170823220139-usd-value-to-activity-feed.up.sql b/resources/migrations/20170823220139-usd-value-to-activity-feed.up.sql new file mode 100644 index 0000000..4923dbd --- /dev/null +++ b/resources/migrations/20170823220139-usd-value-to-activity-feed.up.sql @@ -0,0 +1,96 @@ +drop view if exists claims_view cascade; +drop view if exists activity_feed_view cascade; +drop view if exists bounties_view cascade; +CREATE VIEW claims_view AS SELECT i.title AS issue_title, + i.issue_number, + r.repo AS repo_name, + r.owner AS repo_owner, + coalesce(u.name, u.login) AS user_name, + u.avatar_url AS user_avatar_url, + i.payout_receipt, + p.updated, + i.balance_eth, + i.tokens, + i.value_usd, + p.state AS pr_state + FROM issues i, + users u, + repositories r, + pull_requests p + WHERE r.repo_id = i.repo_id AND p.issue_id = i.issue_id AND p.user_id = u.id AND i.contract_address IS NOT NULL AND i.comment_id IS NOT NULL + ORDER BY p.updated; + +create view bounties_view as +SELECT i.title AS issue_title, + i.issue_number, + r.repo AS repo_name, + r.owner AS repo_owner, + concat(r.owner, '/', r.repo)::character varying(128) AS user_name, + r.owner_avatar_url AS user_avatar_url, + i.payout_receipt, + i.balance_eth, + i.tokens, + i.value_usd, + i.updated + FROM issues i, + repositories r + WHERE r.repo_id = i.repo_id AND i.contract_address IS NOT NULL AND i.comment_id IS NOT NULL + ORDER BY i.updated; + +create view activity_feed_view as + SELECT 'open-claim'::text AS type, + claims_view.issue_title, + claims_view.repo_name, + claims_view.repo_owner, + claims_view.issue_number, + claims_view.user_name, + claims_view.user_avatar_url, + claims_view.balance_eth, + claims_view.tokens, + claims_view.value_usd, + claims_view.updated + FROM claims_view + WHERE claims_view.pr_state = 0 AND claims_view.payout_receipt IS NULL +UNION + SELECT 'claim-payout'::text AS type, + claims_view.issue_title, + claims_view.repo_name, + claims_view.repo_owner, + claims_view.issue_number, + claims_view.user_name, + claims_view.user_avatar_url, + claims_view.balance_eth, + claims_view.tokens, + claims_view.value_usd, + claims_view.updated + FROM claims_view + WHERE claims_view.pr_state = 1 AND claims_view.payout_receipt IS NOT NULL +UNION + SELECT 'new-bounty'::text AS type, + bounties_view.issue_title, + bounties_view.repo_name, + bounties_view.repo_owner, + bounties_view.issue_number, + bounties_view.user_name, + bounties_view.user_avatar_url, + bounties_view.balance_eth, + bounties_view.tokens, + bounties_view.value_usd, + bounties_view.updated + FROM bounties_view + WHERE bounties_view.value_usd = 0::numeric AND bounties_view.payout_receipt IS NULL +UNION +SELECT 'balance-update'::text AS type, + bounties_view.issue_title, + bounties_view.repo_name, + bounties_view.repo_owner, + bounties_view.issue_number, + bounties_view.user_name, + bounties_view.user_avatar_url, + bounties_view.balance_eth, + bounties_view.tokens, + bounties_view.value_usd, + bounties_view.updated + FROM bounties_view + WHERE bounties_view.value_usd > 0::numeric AND bounties_view.payout_receipt IS NULL + ORDER BY 11 DESC;