2016-08-24 22:46:29 +00:00
|
|
|
-- Users ---------------------------------------------------------------------------
|
|
|
|
|
2017-01-15 20:26:33 +00:00
|
|
|
-- :name create-user! :<! :1
|
2016-08-20 21:36:09 +00:00
|
|
|
-- :doc creates a new user record
|
|
|
|
INSERT INTO users
|
2017-03-22 20:20:52 +00:00
|
|
|
(id, login, name, email, avatar_url, address, created)
|
2017-01-15 20:26:33 +00:00
|
|
|
SELECT
|
|
|
|
:id,
|
|
|
|
:login,
|
|
|
|
:name,
|
|
|
|
:email,
|
2017-02-12 20:25:32 +00:00
|
|
|
:avatar_url,
|
2017-01-15 20:26:33 +00:00
|
|
|
:address,
|
|
|
|
:created
|
|
|
|
WHERE NOT exists(SELECT 1
|
|
|
|
FROM users
|
|
|
|
WHERE id = :id)
|
2017-03-23 06:29:40 +00:00
|
|
|
RETURNING id, login, name, email, avatar_url, address, created;
|
2016-08-20 21:36:09 +00:00
|
|
|
|
2018-02-06 14:09:08 +00:00
|
|
|
-- :name user-exists? :? :1
|
|
|
|
-- :doc Checks where a user exists in the database.
|
|
|
|
select 1
|
|
|
|
from users u
|
|
|
|
where u.id = :id;
|
|
|
|
|
2016-08-20 21:36:09 +00:00
|
|
|
-- :name update-user! :! :n
|
2016-08-24 22:46:29 +00:00
|
|
|
-- :doc updates an existing user record
|
2016-08-20 21:36:09 +00:00
|
|
|
UPDATE users
|
2017-02-24 09:05:13 +00:00
|
|
|
SET login = :login,
|
|
|
|
name = :name,
|
|
|
|
email = :email,
|
|
|
|
address = :address
|
2016-08-22 00:22:39 +00:00
|
|
|
WHERE id = :id;
|
|
|
|
|
|
|
|
-- :name update-user-address! :! :n
|
|
|
|
UPDATE users
|
|
|
|
SET address = :address
|
2016-08-28 20:16:45 +00:00
|
|
|
WHERE id = :id;
|
2016-08-20 21:36:09 +00:00
|
|
|
|
|
|
|
-- :name get-user :? :1
|
2017-03-01 20:09:48 +00:00
|
|
|
-- :doc retrieve a user given the user-id.
|
2016-08-22 00:22:39 +00:00
|
|
|
SELECT *
|
|
|
|
FROM users
|
2016-08-28 20:16:45 +00:00
|
|
|
WHERE id = :id;
|
2016-08-20 21:36:09 +00:00
|
|
|
|
2018-04-04 11:23:24 +00:00
|
|
|
-- :name get-user-by-login :? :1
|
|
|
|
-- :doc retrieve a user given GitHub login.
|
|
|
|
SELECT *
|
|
|
|
FROM users
|
|
|
|
WHERE login = :login;
|
|
|
|
|
|
|
|
|
2016-09-09 00:35:28 +00:00
|
|
|
-- :name get-repo-owner :? :1
|
|
|
|
SELECT *
|
2017-02-24 09:05:13 +00:00
|
|
|
FROM users u, repositories r
|
|
|
|
WHERE r.repo_id = :repo_id
|
|
|
|
AND r.user_id = u.id;
|
2016-09-09 00:35:28 +00:00
|
|
|
|
2016-08-24 22:46:29 +00:00
|
|
|
-- Repositories --------------------------------------------------------------------
|
|
|
|
|
2017-02-18 09:07:51 +00:00
|
|
|
-- :name set-repo-state! :<! :1
|
|
|
|
-- :doc sets repository to given state
|
2016-08-24 22:46:29 +00:00
|
|
|
UPDATE repositories
|
2017-02-18 09:07:51 +00:00
|
|
|
SET state = :state
|
2016-08-24 22:46:29 +00:00
|
|
|
WHERE repo_id = :repo_id
|
2017-03-01 20:09:48 +00:00
|
|
|
RETURNING repo_id, owner, repo, state, hook_id;
|
2017-02-18 09:07:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- :name get-repo :? :1
|
2017-03-01 20:09:48 +00:00
|
|
|
-- :doc retrieve a repository given owner and repo-name
|
2017-02-18 09:07:51 +00:00
|
|
|
SELECT *
|
|
|
|
FROM repositories
|
2017-03-01 20:09:48 +00:00
|
|
|
WHERE owner = :owner
|
2017-02-18 09:07:51 +00:00
|
|
|
AND repo = :repo;
|
|
|
|
|
2016-08-24 22:46:29 +00:00
|
|
|
|
|
|
|
-- :name create-repository! :<! :1
|
|
|
|
-- :doc creates repository if not exists
|
2017-03-16 20:37:07 +00:00
|
|
|
INSERT INTO repositories (repo_id, user_id, owner, repo, state, owner_avatar_url)
|
2016-08-24 22:46:29 +00:00
|
|
|
SELECT
|
|
|
|
:repo_id,
|
2016-08-29 22:03:09 +00:00
|
|
|
:user_id,
|
2017-03-01 20:09:48 +00:00
|
|
|
:owner,
|
2016-08-24 22:46:29 +00:00
|
|
|
:repo,
|
2017-03-16 20:37:07 +00:00
|
|
|
:state,
|
|
|
|
:owner_avatar_url
|
2016-08-24 22:46:29 +00:00
|
|
|
WHERE NOT exists(SELECT 1
|
|
|
|
FROM repositories
|
|
|
|
WHERE repo_id = :repo_id)
|
2017-03-16 20:37:07 +00:00
|
|
|
RETURNING repo_id, user_id, owner, repo, state, owner_avatar_url;
|
2016-08-24 22:46:29 +00:00
|
|
|
|
|
|
|
-- :name get-enabled-repositories :? :*
|
2017-03-01 20:09:48 +00:00
|
|
|
-- :doc returns enabled repositories for a given user-id
|
2016-08-24 22:46:29 +00:00
|
|
|
SELECT repo_id
|
|
|
|
FROM repositories
|
2017-02-18 09:07:51 +00:00
|
|
|
WHERE user_id = :user_id
|
|
|
|
AND state = 2;
|
|
|
|
|
2016-08-26 01:10:05 +00:00
|
|
|
|
2017-06-13 07:02:58 +00:00
|
|
|
-- :name get-issue-titles :? :*
|
|
|
|
SELECT i.title, i.issue_number, r.repo, r.owner
|
|
|
|
FROM issues i, repositories r
|
|
|
|
WHERE i.repo_id = r.repo_id;
|
|
|
|
|
2017-10-31 17:05:41 +00:00
|
|
|
-- :name get-issues-count :? :1
|
|
|
|
SELECT COUNT(*)
|
2017-10-31 19:50:27 +00:00
|
|
|
FROM issues i
|
|
|
|
WHERE i.repo_id = :repo_id
|
|
|
|
AND i.confirm_hash is null
|
|
|
|
AND i.is_open = true;
|
2017-06-13 07:02:58 +00:00
|
|
|
|
2018-02-27 15:38:27 +00:00
|
|
|
-- :name update-repo-name :! :n
|
2016-08-26 01:10:05 +00:00
|
|
|
UPDATE repositories
|
2018-02-27 15:38:27 +00:00
|
|
|
SET repo = :repo_name
|
|
|
|
WHERE repo_id = :repo_id
|
|
|
|
AND repo != :repo_name
|
2017-02-18 09:07:51 +00:00
|
|
|
|
2018-02-27 15:38:27 +00:00
|
|
|
-- :name update-repo-state :! :n
|
|
|
|
UPDATE repositories
|
|
|
|
SET state = :repo_state
|
|
|
|
WHERE repo_id = :repo_id
|
2017-02-18 09:07:51 +00:00
|
|
|
|
2016-08-28 20:16:45 +00:00
|
|
|
|
|
|
|
-- Issues --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
-- :name create-issue! :! :n
|
|
|
|
-- :doc creates issue
|
2016-09-06 00:18:33 +00:00
|
|
|
INSERT INTO issues (repo_id, issue_id, issue_number, title)
|
2016-08-28 20:16:45 +00:00
|
|
|
SELECT
|
|
|
|
:repo_id,
|
|
|
|
:issue_id,
|
|
|
|
:issue_number,
|
2016-09-06 00:18:33 +00:00
|
|
|
:title
|
2016-08-28 20:16:45 +00:00
|
|
|
WHERE NOT exists(SELECT 1
|
|
|
|
FROM issues
|
|
|
|
WHERE repo_id = :repo_id AND issue_id = :issue_id);
|
|
|
|
|
2017-02-26 21:40:59 +00:00
|
|
|
-- :name update-commit-sha :<! :1
|
|
|
|
-- :doc updates issue with commit_sha
|
2016-08-28 20:16:45 +00:00
|
|
|
UPDATE issues
|
2017-11-02 10:41:27 +00:00
|
|
|
SET commit_sha = :commit_sha
|
2016-08-28 20:16:45 +00:00
|
|
|
WHERE issue_id = :issue_id
|
2017-02-26 21:40:59 +00:00
|
|
|
RETURNING repo_id, issue_id, issue_number, title, commit_sha, contract_address;
|
2016-09-06 00:18:33 +00:00
|
|
|
|
|
|
|
-- :name update-transaction-hash :! :n
|
|
|
|
-- :doc updates transaction-hash for a given issue
|
|
|
|
UPDATE issues
|
2017-11-02 10:41:27 +00:00
|
|
|
SET transaction_hash = :transaction_hash
|
2016-09-06 00:18:33 +00:00
|
|
|
WHERE issue_id = :issue_id;
|
|
|
|
|
2017-02-24 09:05:13 +00:00
|
|
|
|
|
|
|
-- TODO: this is terrible
|
2016-09-07 00:20:17 +00:00
|
|
|
-- :name update-contract-address :<! :1
|
2016-09-06 00:18:33 +00:00
|
|
|
-- :doc updates contract-address for a given issue
|
2016-09-07 00:20:17 +00:00
|
|
|
WITH t AS (
|
|
|
|
SELECT
|
|
|
|
i.issue_id AS issue_id,
|
|
|
|
i.issue_number AS issue_number,
|
|
|
|
i.title AS title,
|
|
|
|
i.transaction_hash AS transaction_hash,
|
|
|
|
i.contract_address AS contract_address,
|
2017-03-06 18:33:42 +00:00
|
|
|
i.comment_id AS comment_id,
|
2016-09-09 00:35:28 +00:00
|
|
|
i.repo_id AS repo_id,
|
2017-03-01 20:09:48 +00:00
|
|
|
r.owner AS owner,
|
2016-09-07 00:20:17 +00:00
|
|
|
r.repo AS repo
|
2017-02-24 09:05:13 +00:00
|
|
|
FROM issues i, repositories r
|
|
|
|
WHERE r.repo_id = i.repo_id
|
|
|
|
AND i.issue_id = :issue_id
|
2016-09-07 00:20:17 +00:00
|
|
|
)
|
|
|
|
UPDATE issues i
|
2017-02-26 21:40:59 +00:00
|
|
|
SET contract_address = :contract_address,
|
|
|
|
updated = timezone('utc'::text, now())
|
2016-09-07 00:20:17 +00:00
|
|
|
FROM t
|
2016-09-19 21:43:32 +00:00
|
|
|
WHERE i.issue_id = :issue_id
|
2017-03-06 18:33:42 +00:00
|
|
|
RETURNING t.issue_id, t.issue_number, t.title, t.transaction_hash, t.comment_id, i.contract_address, t.owner, t.repo, t.repo_id;
|
2016-09-06 00:18:33 +00:00
|
|
|
|
2016-09-12 16:50:32 +00:00
|
|
|
-- :name update-comment-id :! :n
|
2016-09-12 16:44:29 +00:00
|
|
|
-- :doc updates comment-id for a given issue
|
|
|
|
UPDATE issues
|
2017-02-26 21:40:59 +00:00
|
|
|
SET comment_id = :comment_id,
|
|
|
|
updated = timezone('utc'::text, now())
|
2016-09-12 16:44:29 +00:00
|
|
|
WHERE issue_id = :issue_id;
|
|
|
|
|
2017-06-13 07:02:58 +00:00
|
|
|
-- :name update-issue-title :! :n
|
|
|
|
-- :doc updates title for a given issue-id
|
|
|
|
UPDATE issues
|
|
|
|
SET title = :title
|
|
|
|
WHERE issue_id = :issue_id;
|
|
|
|
|
2016-09-06 00:18:33 +00:00
|
|
|
-- :name list-pending-deployments :? :*
|
|
|
|
-- :doc retrieves pending transaction ids
|
|
|
|
SELECT
|
2017-05-31 07:02:07 +00:00
|
|
|
i.issue_id as issue_id,
|
|
|
|
i.transaction_hash as transaction_hash,
|
|
|
|
u.address as owner_address
|
|
|
|
FROM issues i, users u, repositories r
|
|
|
|
WHERE r.user_id = u.id
|
|
|
|
AND i.repo_id = r.repo_id
|
|
|
|
AND i.contract_address IS NULL
|
|
|
|
AND i.transaction_hash IS NOT NULL;
|
2016-08-28 20:16:45 +00:00
|
|
|
|
2017-05-31 07:44:45 +00:00
|
|
|
|
2016-08-28 20:16:45 +00:00
|
|
|
-- Pull Requests -------------------------------------------------------------------
|
|
|
|
|
2017-02-24 09:05:13 +00:00
|
|
|
-- :name save-pull-request! :! :n
|
|
|
|
-- :doc inserts or updates a pull request record
|
|
|
|
INSERT INTO pull_requests (pr_id,
|
|
|
|
repo_id,
|
|
|
|
pr_number,
|
2018-03-14 16:49:00 +00:00
|
|
|
title,
|
2017-02-24 09:05:13 +00:00
|
|
|
issue_number,
|
2017-02-24 22:15:44 +00:00
|
|
|
issue_id,
|
2017-02-26 21:40:59 +00:00
|
|
|
commit_sha,
|
2017-02-24 09:05:13 +00:00
|
|
|
user_id,
|
|
|
|
state)
|
|
|
|
VALUES(:pr_id,
|
|
|
|
:repo_id,
|
|
|
|
:pr_number,
|
2018-03-14 16:49:00 +00:00
|
|
|
:title,
|
2017-02-24 09:05:13 +00:00
|
|
|
:issue_number,
|
2017-02-24 22:15:44 +00:00
|
|
|
:issue_id,
|
2017-02-26 21:40:59 +00:00
|
|
|
:commit_sha,
|
2017-02-24 09:05:13 +00:00
|
|
|
:user_id,
|
|
|
|
:state)
|
2018-04-10 15:17:31 +00:00
|
|
|
ON CONFLICT (pr_id,issue_id) DO UPDATE
|
2017-02-24 09:05:13 +00:00
|
|
|
SET
|
|
|
|
state = :state,
|
2017-11-02 21:14:42 +00:00
|
|
|
issue_number = :issue_number,
|
|
|
|
issue_id = :issue_id,
|
2018-03-14 16:49:00 +00:00
|
|
|
title = :title,
|
2017-02-24 22:15:44 +00:00
|
|
|
updated = timezone('utc'::text, now()),
|
2017-02-26 21:40:59 +00:00
|
|
|
commit_sha = :commit_sha;
|
2016-08-28 20:16:45 +00:00
|
|
|
|
2017-11-03 10:35:42 +00:00
|
|
|
|
|
|
|
-- :name remove-pull-request! :! :n
|
|
|
|
-- :doc remove a PR by id
|
|
|
|
DELETE from pull_requests
|
|
|
|
WHERE pr_id = :pr_id;
|
|
|
|
|
|
|
|
|
2016-08-28 20:16:45 +00:00
|
|
|
-- Bounties ------------------------------------------------------------------------
|
|
|
|
|
2017-03-12 17:50:05 +00:00
|
|
|
|
|
|
|
-- :name pending-contracts :? :*
|
|
|
|
-- :doc bounty issues where deploy contract has failed
|
|
|
|
SELECT
|
|
|
|
i.issue_id AS issue_id,
|
2018-03-01 15:52:17 +00:00
|
|
|
i.issue_number AS issue_number,
|
2018-03-22 11:17:30 +00:00
|
|
|
r.owner AS owner,
|
2018-03-01 15:52:17 +00:00
|
|
|
u.address AS owner_address,
|
|
|
|
r.repo AS repo
|
2017-03-12 17:50:05 +00:00
|
|
|
FROM issues i, users u, repositories r
|
|
|
|
WHERE
|
|
|
|
r.user_id = u.id
|
|
|
|
AND i.repo_id = r.repo_id
|
|
|
|
AND i.transaction_hash IS NULL
|
|
|
|
AND i.contract_address IS NULL;
|
|
|
|
|
|
|
|
|
2017-03-19 14:07:42 +00:00
|
|
|
-- :name pending-bounties :? :*
|
2017-03-19 20:13:09 +00:00
|
|
|
-- :doc bounties with merged pull-requests awaiting to be signed
|
2016-09-09 23:06:56 +00:00
|
|
|
SELECT
|
|
|
|
i.contract_address AS contract_address,
|
2017-03-19 20:13:09 +00:00
|
|
|
r.owner AS owner,
|
|
|
|
r.repo AS repo,
|
|
|
|
i.comment_id AS comment_id,
|
|
|
|
i.issue_number AS issue_number,
|
2016-09-09 23:06:56 +00:00
|
|
|
i.issue_id AS issue_id,
|
2017-08-23 20:47:50 +00:00
|
|
|
i.balance_eth AS balance_eth,
|
2017-08-22 13:45:10 +00:00
|
|
|
i.tokens AS tokens,
|
2017-08-23 20:47:50 +00:00
|
|
|
i.value_usd AS value_usd,
|
2017-03-19 20:13:09 +00:00
|
|
|
u.login AS winner_login,
|
2016-09-09 23:06:56 +00:00
|
|
|
u.address AS payout_address
|
2017-03-19 20:13:09 +00:00
|
|
|
FROM issues i, pull_requests p, users u, repositories r
|
2017-02-24 09:05:13 +00:00
|
|
|
WHERE
|
2017-02-24 22:15:44 +00:00
|
|
|
p.issue_id = i.issue_id
|
2017-02-24 09:05:13 +00:00
|
|
|
AND p.repo_id = i.repo_id
|
2017-03-19 20:13:09 +00:00
|
|
|
AND p.commit_sha = i.commit_sha
|
|
|
|
AND r.repo_id = i.repo_id
|
2017-02-24 09:05:13 +00:00
|
|
|
AND u.id = p.user_id
|
|
|
|
AND i.execute_hash IS NULL;
|
2016-10-01 12:29:18 +00:00
|
|
|
|
2017-03-19 14:07:42 +00:00
|
|
|
-- :name pending-payouts :? :*
|
2017-06-13 16:26:48 +00:00
|
|
|
-- :doc recently closed issues awaiting for bot confirmation to be mined
|
2016-10-01 12:29:18 +00:00
|
|
|
SELECT
|
|
|
|
i.contract_address AS contract_address,
|
|
|
|
i.issue_id AS issue_id,
|
2017-02-24 22:15:44 +00:00
|
|
|
u.address AS payout_address,
|
|
|
|
i.execute_hash AS execute_hash
|
2017-02-24 09:05:13 +00:00
|
|
|
FROM issues i, pull_requests p, users u
|
|
|
|
WHERE
|
2017-02-24 22:15:44 +00:00
|
|
|
p.issue_id = i.issue_id
|
2017-02-24 09:05:13 +00:00
|
|
|
AND p.repo_id = i.repo_id
|
|
|
|
AND u.id = p.user_id
|
|
|
|
AND i.confirm_hash IS NULL
|
|
|
|
AND i.execute_hash IS NOT NULL;
|
2016-09-09 23:06:56 +00:00
|
|
|
|
2017-03-19 14:07:42 +00:00
|
|
|
-- :name confirmed-payouts :? :*
|
2016-10-04 00:13:43 +00:00
|
|
|
-- :doc lists all recently confirmed bounty payouts
|
|
|
|
SELECT
|
|
|
|
i.contract_address AS contract_address,
|
2017-03-19 15:10:56 +00:00
|
|
|
r.owner AS owner,
|
|
|
|
r.repo AS repo,
|
|
|
|
i.comment_id AS comment_id,
|
|
|
|
i.issue_number AS issue_number,
|
2016-10-04 00:13:43 +00:00
|
|
|
i.issue_id AS issue_id,
|
2017-08-23 20:47:50 +00:00
|
|
|
i.balance_eth AS balance_eth,
|
2017-08-22 13:45:10 +00:00
|
|
|
i.tokens AS tokens,
|
2017-08-23 20:47:50 +00:00
|
|
|
i.value_usd AS value_usd,
|
2017-02-24 22:15:44 +00:00
|
|
|
u.address AS payout_address,
|
2017-03-19 15:10:56 +00:00
|
|
|
u.login AS payee_login,
|
2017-08-31 08:33:08 +00:00
|
|
|
i.confirm_hash AS confirm_hash,
|
2017-09-15 07:24:55 +00:00
|
|
|
i.payout_hash AS payout_hash,
|
|
|
|
i.updated AS updated
|
2017-03-19 15:10:56 +00:00
|
|
|
FROM issues i, pull_requests p, users u, repositories r
|
2017-02-24 09:05:13 +00:00
|
|
|
WHERE
|
2017-02-24 22:15:44 +00:00
|
|
|
p.issue_id = i.issue_id
|
2017-02-24 09:05:13 +00:00
|
|
|
AND p.repo_id = i.repo_id
|
2017-03-19 15:10:56 +00:00
|
|
|
AND r.repo_id = i.repo_id
|
2017-11-07 16:16:38 +00:00
|
|
|
AND p.state = 1
|
2017-02-24 09:05:13 +00:00
|
|
|
AND u.id = p.user_id
|
|
|
|
AND i.payout_receipt IS NULL
|
|
|
|
AND i.payout_hash IS NOT NULL;
|
2016-10-04 00:13:43 +00:00
|
|
|
|
2016-09-09 23:06:56 +00:00
|
|
|
-- :name update-confirm-hash :! :n
|
2016-10-01 12:29:18 +00:00
|
|
|
-- :doc updates issue with confirmation hash
|
2016-09-09 23:06:56 +00:00
|
|
|
UPDATE issues
|
2017-02-26 21:40:59 +00:00
|
|
|
SET confirm_hash = :confirm_hash,
|
|
|
|
updated = timezone('utc'::text, now())
|
2016-09-09 23:06:56 +00:00
|
|
|
WHERE issue_id = :issue_id;
|
|
|
|
|
2016-10-01 12:29:18 +00:00
|
|
|
-- :name update-execute-hash :! :n
|
|
|
|
-- :doc updates issue with execute transaction hash
|
|
|
|
UPDATE issues
|
2017-02-26 21:40:59 +00:00
|
|
|
SET execute_hash = :execute_hash,
|
|
|
|
updated = timezone('utc'::text, now())
|
2016-10-01 12:29:18 +00:00
|
|
|
WHERE issue_id = :issue_id;
|
|
|
|
|
2017-11-02 13:48:40 +00:00
|
|
|
-- :name update-winner-login :! :n
|
|
|
|
UPDATE issues
|
|
|
|
SET winner_login = :winner_login
|
|
|
|
WHERE issue_id = :issue_id;
|
|
|
|
|
2017-12-18 17:31:53 +00:00
|
|
|
-- :name update-watch-hash :! :n
|
|
|
|
-- :doc updates issue with watch transaction hash
|
|
|
|
UPDATE issues
|
|
|
|
SET watch_hash = :watch_hash
|
|
|
|
WHERE issue_id = :issue_id;
|
|
|
|
|
|
|
|
-- :name pending-watch-calls :? :*
|
|
|
|
-- :doc issues with a pending watch transaction
|
|
|
|
SELECT
|
|
|
|
issue_id,
|
|
|
|
watch_hash
|
|
|
|
FROM issues
|
|
|
|
WHERE watch_hash IS NOT NULL;
|
|
|
|
|
|
|
|
|
2016-10-04 00:13:43 +00:00
|
|
|
-- :name update-payout-hash :! :n
|
|
|
|
-- :doc updates issue with payout transaction hash
|
|
|
|
UPDATE issues
|
2017-02-26 21:40:59 +00:00
|
|
|
SET payout_hash = :payout_hash,
|
|
|
|
updated = timezone('utc'::text, now())
|
2016-10-04 00:13:43 +00:00
|
|
|
WHERE issue_id = :issue_id;
|
|
|
|
|
2017-09-15 07:24:55 +00:00
|
|
|
-- :name reset-payout-hash :! :n
|
|
|
|
-- :doc sets issue's payout transaction hash to NULL
|
|
|
|
UPDATE issues
|
2017-11-02 13:48:40 +00:00
|
|
|
SET payout_hash = NULL,
|
|
|
|
winner_login = NULL
|
2017-09-15 07:24:55 +00:00
|
|
|
WHERE issue_id = :issue_id;
|
|
|
|
|
|
|
|
|
2016-10-04 00:13:43 +00:00
|
|
|
-- :name update-payout-receipt :! :n
|
|
|
|
-- :doc updates issue with payout transaction receipt
|
|
|
|
UPDATE issues
|
2017-03-09 19:50:57 +00:00
|
|
|
SET payout_receipt = :payout_receipt::jsonb,
|
2017-02-26 21:40:59 +00:00
|
|
|
updated = timezone('utc'::text, now())
|
2016-10-04 00:13:43 +00:00
|
|
|
WHERE issue_id = :issue_id;
|
|
|
|
|
2016-09-19 20:26:57 +00:00
|
|
|
|
2017-08-22 13:45:10 +00:00
|
|
|
-- :name update-token-balances :! :n
|
|
|
|
-- :doc updates issue with given token balances
|
|
|
|
UPDATE issues
|
|
|
|
SET tokens = :token_balances::jsonb,
|
|
|
|
updated = timezone('utc'::text, now())
|
|
|
|
WHERE contract_address = :contract_address;
|
|
|
|
|
|
|
|
|
2017-08-22 17:27:01 +00:00
|
|
|
-- :name update-usd-value :! :n
|
|
|
|
-- :doc updates issue with given USD value
|
|
|
|
UPDATE issues
|
2017-08-22 19:15:40 +00:00
|
|
|
SET value_usd = :usd_value,
|
|
|
|
value_usd_updated = timezone('utc'::text, now())
|
2017-08-22 17:27:01 +00:00
|
|
|
WHERE contract_address = :contract_address;
|
|
|
|
|
|
|
|
|
2017-09-13 08:09:48 +00:00
|
|
|
-- :name update-issue-open :! :n
|
|
|
|
-- :doc updates issue's open status
|
|
|
|
UPDATE issues
|
|
|
|
SET is_open = :is_open
|
|
|
|
WHERE issue_id = :issue_id;
|
|
|
|
|
|
|
|
|
|
|
|
-- :name issue-exists :1
|
2017-09-13 08:20:11 +00:00
|
|
|
-- :doc returns true if given issue exists
|
2017-09-13 08:09:48 +00:00
|
|
|
SELECT exists(SELECT 1
|
|
|
|
FROM issues
|
|
|
|
WHERE issue_id = :issue_id);
|
|
|
|
|
2018-03-01 14:55:44 +00:00
|
|
|
-- :name get-issue :? :1
|
|
|
|
-- :doc get issue from DB by repo-id and issue-number
|
|
|
|
SELECT issue_id, issue_number, is_open, winner_login, commit_sha
|
|
|
|
FROM issues
|
|
|
|
WHERE repo_id = :repo_id
|
|
|
|
AND issue_number = :issue_number;
|
|
|
|
|
|
|
|
|
2017-09-13 08:09:48 +00:00
|
|
|
|
2017-03-17 20:59:03 +00:00
|
|
|
-- :name open-bounties :? :*
|
2017-12-07 17:31:05 +00:00
|
|
|
-- :doc all open bounty issues
|
2017-03-17 20:59:03 +00:00
|
|
|
SELECT
|
|
|
|
i.contract_address AS contract_address,
|
|
|
|
i.issue_id AS issue_id,
|
|
|
|
i.issue_number AS issue_number,
|
|
|
|
i.title AS issue_title,
|
|
|
|
i.repo_id AS repo_id,
|
2017-08-23 20:47:50 +00:00
|
|
|
i.balance_eth AS balance_eth,
|
2017-08-22 13:45:10 +00:00
|
|
|
i.tokens AS tokens,
|
2017-08-23 20:47:50 +00:00
|
|
|
i.value_usd AS value_usd,
|
2017-03-17 20:59:03 +00:00
|
|
|
i.confirm_hash AS confirm_hash,
|
|
|
|
i.payout_hash AS payout_hash,
|
|
|
|
i.payout_receipt AS payout_receipt,
|
|
|
|
i.updated AS updated,
|
|
|
|
r.owner AS repo_owner,
|
|
|
|
r.owner_avatar_url AS repo_owner_avatar_url,
|
2017-11-08 10:38:22 +00:00
|
|
|
r.repo AS repo_name,
|
|
|
|
(SELECT count(*) FROM pull_requests WHERE issue_id = i.issue_id AND state = 0) AS claim_count
|
2017-03-17 20:59:03 +00:00
|
|
|
FROM issues i, repositories r
|
|
|
|
WHERE
|
|
|
|
r.repo_id = i.repo_id
|
2017-12-07 17:31:05 +00:00
|
|
|
AND i.contract_address IS NOT NULL
|
|
|
|
AND i.confirm_hash IS NULL
|
2017-10-29 18:05:51 +00:00
|
|
|
AND i.is_open = true
|
2017-10-30 20:19:01 +00:00
|
|
|
ORDER BY updated desc;
|
2017-03-17 20:59:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- :name owner-bounties :? :*
|
2017-02-24 22:15:44 +00:00
|
|
|
-- :doc all bounty issues for given owner
|
2016-08-28 20:16:45 +00:00
|
|
|
SELECT
|
2016-09-06 00:18:33 +00:00
|
|
|
i.contract_address AS contract_address,
|
|
|
|
i.issue_id AS issue_id,
|
|
|
|
i.issue_number AS issue_number,
|
|
|
|
i.title AS issue_title,
|
|
|
|
i.repo_id AS repo_id,
|
2017-08-22 13:45:10 +00:00
|
|
|
i.balance_eth AS balance_eth,
|
|
|
|
i.tokens AS tokens,
|
2017-08-23 20:47:50 +00:00
|
|
|
i.value_usd AS value_usd,
|
2016-09-22 00:44:45 +00:00
|
|
|
i.confirm_hash AS confirm_hash,
|
2016-10-04 00:13:43 +00:00
|
|
|
i.payout_hash AS payout_hash,
|
|
|
|
i.payout_receipt AS payout_receipt,
|
2017-02-27 20:38:41 +00:00
|
|
|
i.updated AS updated,
|
2017-11-02 14:39:59 +00:00
|
|
|
i.winner_login AS winner_login,
|
2017-02-24 22:15:44 +00:00
|
|
|
r.repo AS repo_name,
|
2018-02-21 17:17:32 +00:00
|
|
|
o.address AS owner_address,
|
|
|
|
u.address AS payout_address
|
|
|
|
FROM users o, repositories r, issues i LEFT OUTER JOIN users u ON u.login = i.winner_login
|
2017-02-24 22:15:44 +00:00
|
|
|
WHERE
|
|
|
|
r.repo_id = i.repo_id
|
|
|
|
AND r.user_id = o.id
|
|
|
|
AND r.user_id = :owner_id;
|
|
|
|
|
|
|
|
|
|
|
|
-- :name bounty-claims :? :*
|
|
|
|
-- :doc open, merged and closed PRs referencing given bounty issue
|
|
|
|
SELECT
|
|
|
|
i.contract_address AS contract_address,
|
|
|
|
i.issue_id AS issue_id,
|
|
|
|
i.issue_number AS issue_number,
|
|
|
|
i.title AS issue_title,
|
|
|
|
i.repo_id AS repo_id,
|
2017-08-23 20:47:50 +00:00
|
|
|
i.balance_eth AS balance_eth,
|
2017-08-22 13:45:10 +00:00
|
|
|
i.tokens AS tokens,
|
2017-08-23 20:47:50 +00:00
|
|
|
i.value_usd AS value_usd,
|
2017-02-24 22:15:44 +00:00
|
|
|
i.confirm_hash AS confirm_hash,
|
|
|
|
i.payout_hash AS payout_hash,
|
|
|
|
i.payout_receipt AS payout_receipt,
|
|
|
|
p.state AS pr_state,
|
2016-09-06 00:18:33 +00:00
|
|
|
p.pr_id AS pr_id,
|
|
|
|
p.user_id AS user_id,
|
|
|
|
p.pr_number AS pr_number,
|
|
|
|
u.address AS payout_address,
|
|
|
|
u.login AS user_login,
|
|
|
|
u.name AS user_name,
|
2017-02-24 22:15:44 +00:00
|
|
|
u.avatar_url AS user_avatar_url,
|
2017-03-01 20:09:48 +00:00
|
|
|
r.owner AS repo_owner,
|
2016-09-22 00:44:45 +00:00
|
|
|
r.repo AS repo_name,
|
|
|
|
o.address AS owner_address
|
2017-02-24 09:05:13 +00:00
|
|
|
FROM issues i, pull_requests p, users u, users o, repositories r
|
|
|
|
WHERE
|
2017-02-24 22:15:44 +00:00
|
|
|
p.issue_id = i.issue_id
|
2017-02-24 09:05:13 +00:00
|
|
|
AND p.repo_id = i.repo_id
|
|
|
|
AND u.id = p.user_id
|
|
|
|
AND r.repo_id = i.repo_id
|
|
|
|
AND r.user_id = o.id
|
2017-02-24 22:15:44 +00:00
|
|
|
AND i.issue_id = :issue_id;
|
|
|
|
|
|
|
|
|
2017-02-24 09:05:13 +00:00
|
|
|
-- :name open-bounty-contracts :? :*
|
|
|
|
-- :doc bounty issues with mined bounty contracts
|
2016-09-12 16:44:29 +00:00
|
|
|
SELECT
|
|
|
|
i.contract_address AS contract_address,
|
2017-03-01 20:09:48 +00:00
|
|
|
r.owner AS owner,
|
2016-09-12 16:44:29 +00:00
|
|
|
r.repo AS repo,
|
|
|
|
i.comment_id AS comment_id,
|
2017-02-21 08:49:25 +00:00
|
|
|
i.issue_number AS issue_number,
|
|
|
|
i.issue_id AS issue_id,
|
2017-08-23 20:47:50 +00:00
|
|
|
i.balance_eth AS balance_eth,
|
|
|
|
i.tokens AS tokens,
|
2017-12-18 17:31:53 +00:00
|
|
|
i.value_usd AS value_usd,
|
|
|
|
i.watch_hash AS watch_hash
|
2017-02-24 09:05:13 +00:00
|
|
|
FROM issues i, repositories r
|
|
|
|
WHERE r.repo_id = i.repo_id
|
|
|
|
AND contract_address IS NOT NULL
|
2017-12-04 10:47:02 +00:00
|
|
|
AND i.execute_hash IS NULL
|
2017-11-07 11:44:58 +00:00
|
|
|
AND i.is_open = true;
|
2016-09-10 06:50:13 +00:00
|
|
|
|
2017-02-21 08:49:25 +00:00
|
|
|
-- :name get-bounty :? :1
|
2017-02-24 09:05:13 +00:00
|
|
|
-- :doc details for a bounty issue given owner, repo and issue nunber
|
2016-09-11 23:15:59 +00:00
|
|
|
SELECT
|
|
|
|
i.contract_address AS contract_address,
|
2017-02-21 08:49:25 +00:00
|
|
|
i.issue_id AS issue_id,
|
2016-09-11 23:15:59 +00:00
|
|
|
i.issue_number AS issue_number,
|
2017-08-23 20:47:50 +00:00
|
|
|
i.balance_eth AS balance_eth,
|
2017-08-22 13:45:10 +00:00
|
|
|
i.tokens AS tokens,
|
2017-08-23 20:47:50 +00:00
|
|
|
i.value_usd AS value_usd,
|
2017-03-01 20:09:48 +00:00
|
|
|
r.owner AS owner,
|
2017-02-24 22:15:44 +00:00
|
|
|
r.repo AS repo
|
2017-02-24 09:05:13 +00:00
|
|
|
FROM issues i, repositories r
|
2016-09-10 06:50:13 +00:00
|
|
|
WHERE i.issue_number = :issue_number
|
2017-02-24 09:05:13 +00:00
|
|
|
AND r.repo_id = i.repo_id
|
2017-03-01 20:09:48 +00:00
|
|
|
AND r.owner = :owner
|
2017-02-24 09:05:13 +00:00
|
|
|
AND r.repo = :repo;
|
2016-09-13 16:50:04 +00:00
|
|
|
|
2017-08-22 13:45:10 +00:00
|
|
|
-- :name update-eth-balance :! :n
|
2016-09-13 16:50:04 +00:00
|
|
|
-- :doc updates balance of a wallet attached to a given issue
|
|
|
|
UPDATE issues
|
2017-08-23 20:47:50 +00:00
|
|
|
SET balance_eth = :balance_eth,
|
2017-02-26 21:40:59 +00:00
|
|
|
updated = timezone('utc'::text, now())
|
2016-09-13 16:50:04 +00:00
|
|
|
WHERE contract_address = :contract_address;
|
2017-02-21 08:49:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- :name save-issue-comment-image! :<! :1
|
2017-02-24 09:05:13 +00:00
|
|
|
-- :doc insert or update image data for a given issue's github comment
|
2017-03-01 20:09:48 +00:00
|
|
|
INSERT INTO issue_comment (issue_id, comment_hash, png_data)
|
|
|
|
VALUES (:issue_id, :hash, :png_data)
|
|
|
|
ON CONFLICT (issue_id, comment_hash) DO UPDATE
|
2017-02-21 08:49:25 +00:00
|
|
|
SET png_data = :png_data
|
|
|
|
RETURNING id;
|
|
|
|
|
|
|
|
|
|
|
|
-- :name get-issue-comment-image :? :1
|
2017-02-24 09:05:13 +00:00
|
|
|
-- :doc retrieve image data for given issue's github comment
|
2017-02-21 08:49:25 +00:00
|
|
|
SELECT png_data
|
|
|
|
FROM issue_comment
|
2017-03-01 20:09:48 +00:00
|
|
|
WHERE issue_id = :issue_id
|
|
|
|
AND comment_hash = :hash;
|
2017-02-26 14:14:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- :name top-hunters :? :*
|
2017-12-21 11:45:06 +00:00
|
|
|
-- :doc top 5 list of users that have reveived bounty payouts with sum of
|
2017-02-26 21:40:59 +00:00
|
|
|
-- earnings
|
2017-02-26 14:14:39 +00:00
|
|
|
SELECT
|
|
|
|
u.id AS user_id,
|
|
|
|
u.login AS login,
|
2017-10-25 11:56:24 +00:00
|
|
|
coalesce(u.name, u.login) AS user_name,
|
2017-02-26 14:14:39 +00:00
|
|
|
u.avatar_url AS avatar_url,
|
2017-08-23 20:47:50 +00:00
|
|
|
SUM(i.value_usd) AS total_usd
|
2017-02-26 14:14:39 +00:00
|
|
|
FROM issues i, users u, pull_requests pr
|
|
|
|
WHERE
|
2017-02-26 21:40:59 +00:00
|
|
|
pr.commit_sha = i.commit_sha
|
2017-02-26 14:14:39 +00:00
|
|
|
AND u.id = pr.user_id
|
|
|
|
AND i.payout_receipt IS NOT NULL
|
2018-02-08 12:29:26 +00:00
|
|
|
AND NOT u.is_hidden_in_hunters
|
2017-02-26 14:14:39 +00:00
|
|
|
GROUP BY u.id
|
2017-12-21 09:44:34 +00:00
|
|
|
ORDER BY total_usd DESC
|
2017-12-21 11:45:06 +00:00
|
|
|
LIMIT 5;
|
2017-02-26 21:40:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- :name bounties-activity :? :*
|
|
|
|
-- :doc data for bounty activity feed
|
|
|
|
SELECT
|
|
|
|
type,
|
|
|
|
issue_title,
|
|
|
|
repo_name,
|
2017-02-27 20:38:41 +00:00
|
|
|
repo_owner,
|
2018-03-14 16:49:00 +00:00
|
|
|
pr_number,
|
|
|
|
pr_title,
|
|
|
|
pr_id,
|
2017-02-26 21:40:59 +00:00
|
|
|
issue_number,
|
2018-04-12 19:07:51 +00:00
|
|
|
issue_id,
|
2017-02-26 21:40:59 +00:00
|
|
|
user_name,
|
|
|
|
user_avatar_url,
|
2017-08-23 20:47:50 +00:00
|
|
|
balance_eth,
|
|
|
|
tokens,
|
|
|
|
value_usd,
|
2017-11-09 14:55:40 +00:00
|
|
|
user_has_address,
|
2017-02-26 21:40:59 +00:00
|
|
|
updated
|
|
|
|
FROM activity_feed_view
|
|
|
|
ORDER BY updated DESC
|
|
|
|
LIMIT 100;
|
2017-04-02 17:20:44 +00:00
|
|
|
|
2017-10-28 18:10:09 +00:00
|
|
|
-- :name get-new-users-for-welcome-email :? :*
|
|
|
|
-- :doc users who have not been sent a welcome email
|
|
|
|
SELECT
|
|
|
|
id,
|
|
|
|
login,
|
|
|
|
email,
|
|
|
|
name
|
|
|
|
FROM users
|
|
|
|
WHERE welcome_email_sent = 0;
|
|
|
|
|
2017-04-02 17:20:44 +00:00
|
|
|
|
|
|
|
-- :name usage-metrics-by-day :? :*
|
|
|
|
-- :doc data for usage metrics chart
|
|
|
|
SELECT * FROM (
|
|
|
|
SELECT d.DAY,
|
|
|
|
coalesce(max(registered_users), (SELECT max(registered_users) FROM usage_metrics WHERE change_timestamp < d.day)) AS registered_users,
|
|
|
|
coalesce(max(users_with_address), (SELECT max(users_with_address) FROM usage_metrics WHERE change_timestamp < d.day)) AS users_with_address
|
|
|
|
FROM
|
|
|
|
(SELECT day FROM generate_series(CURRENT_DATE - INTERVAL '365 day', CURRENT_DATE, '1 day'::interval) AS day) AS d
|
|
|
|
LEFT OUTER JOIN usage_metrics um
|
|
|
|
ON d.day = date_trunc('day', um.change_timestamp)
|
|
|
|
GROUP BY d.day
|
|
|
|
ORDER BY 1 desc
|
|
|
|
LIMIT :limit_days) AS a
|
|
|
|
ORDER BY a.day ASC;
|