From 9769771bc2427a5e64b7c0a14b8e7fe3798db04b Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Mon, 7 Sep 2015 19:01:41 -0400 Subject: [PATCH] Clean up SQL scripts and schema after #3744 --- sql/1.0/all.sql | 4 ---- sql/1.0/compute-balances.sql | 16 ---------------- sql/1.0/identify-receivers.sql | 10 ---------- sql/1.0/prep-numbers.sql | 32 -------------------------------- sql/1.0/set-status.sql | 15 --------------- sql/branch.sql | 5 +++++ 6 files changed, 5 insertions(+), 77 deletions(-) delete mode 100644 sql/1.0/all.sql delete mode 100644 sql/1.0/compute-balances.sql delete mode 100644 sql/1.0/identify-receivers.sql delete mode 100644 sql/1.0/prep-numbers.sql delete mode 100644 sql/1.0/set-status.sql create mode 100644 sql/branch.sql diff --git a/sql/1.0/all.sql b/sql/1.0/all.sql deleted file mode 100644 index c1bcffdedf..0000000000 --- a/sql/1.0/all.sql +++ /dev/null @@ -1,4 +0,0 @@ -\i sql/1.0/identify-receivers.sql -\i sql/1.0/prep-numbers.sql -\i sql/1.0/compute-balances.sql -\i sql/1.0/set-status.sql diff --git a/sql/1.0/compute-balances.sql b/sql/1.0/compute-balances.sql deleted file mode 100644 index ba5ac21f0d..0000000000 --- a/sql/1.0/compute-balances.sql +++ /dev/null @@ -1,16 +0,0 @@ --- Manually correct two users per https://github.com/gratipay/gratipay.com/issues/3453 --- The other two affected users there currently have a zero balance, so they're --- not included in receiving_1_0 (any Gratipay 1.0 money they accumulated is --- already gone). - -UPDATE numbers_1_0 - SET paid_in = paid_in - paid_out, paid_out = 0 - WHERE participant IN ('webmaven', 'whit537'); - - --- Compute balance at the Gratipocalypse, and 1.0 balance that remains. - -UPDATE numbers_1_0 SET at_gratipocalypse = - (balance - paid_in + paid_out - transferred_to + transferred_from - paid_to + paid_from); -UPDATE numbers_1_0 SET remaining = - (at_gratipocalypse - paid_out - transferred_from - paid_from); diff --git a/sql/1.0/identify-receivers.sql b/sql/1.0/identify-receivers.sql deleted file mode 100644 index 54666cb8fc..0000000000 --- a/sql/1.0/identify-receivers.sql +++ /dev/null @@ -1,10 +0,0 @@ -DROP TABLE IF EXISTS receivers_1_0; -CREATE TABLE receivers_1_0 AS ( - SELECT DISTINCT ON (tippee) - tippee AS participant - , balance - FROM transfers t - JOIN participants p ON t.tippee = p.username - WHERE "timestamp" < '2015-05-07'::timestamptz - AND balance > 0 -); diff --git a/sql/1.0/prep-numbers.sql b/sql/1.0/prep-numbers.sql deleted file mode 100644 index a498ec64a2..0000000000 --- a/sql/1.0/prep-numbers.sql +++ /dev/null @@ -1,32 +0,0 @@ -DROP TABLE IF EXISTS numbers_1_0; -CREATE TABLE numbers_1_0 AS ( - SELECT r.participant - , r.balance - - , (SELECT coalesce(sum(amount), 0) FROM exchanges - WHERE participant=r.participant AND "timestamp" > '2015-05-07' AND amount > 0 - AND status != 'failed') AS paid_in - , (SELECT -coalesce(sum(amount - fee), 0) FROM exchanges - WHERE participant=r.participant AND "timestamp" > '2015-05-07' AND amount < 0 - AND status != 'failed') AS paid_out - - , (SELECT coalesce(sum(amount), 0) FROM transfers t - WHERE t.tippee=r.participant AND "timestamp" > '2015-05-07') - AS transferred_to - , (SELECT coalesce(sum(amount), 0) FROM transfers t - WHERE t.tipper=r.participant AND "timestamp" > '2015-05-07') - AS transferred_from - - , (SELECT coalesce(sum(amount), 0) FROM payments p - WHERE p.participant=r.participant AND "timestamp" > '2015-05-07' - AND direction='to-participant') AS paid_to - , (SELECT coalesce(sum(amount), 0) FROM payments p - WHERE p.participant=r.participant AND "timestamp" > '2015-05-07' - AND direction='to-team') AS paid_from - - , 0::numeric(35,2) AS at_gratipocalypse - , 0::numeric(35,2) AS remaining - - FROM receivers_1_0 r -ORDER BY balance DESC, participant -); diff --git a/sql/1.0/set-status.sql b/sql/1.0/set-status.sql deleted file mode 100644 index debaffdc99..0000000000 --- a/sql/1.0/set-status.sql +++ /dev/null @@ -1,15 +0,0 @@ -UPDATE participants - SET status_of_1_0_payout = 'pending-application' - WHERE username = ANY(SELECT participant FROM numbers_1_0 WHERE remaining > 0); - -UPDATE participants - SET status_of_1_0_payout='pending-payout' - WHERE status_of_1_0_balance='pending-payout'; - -UPDATE participants - SET status_of_1_0_payout='completed' - WHERE status_of_1_0_balance='resolved'; - -UPDATE participants - SET status_of_1_0_payout = 'too-little' - WHERE status_of_1_0_payout = 'pending-application' and balance < 0.50; diff --git a/sql/branch.sql b/sql/branch.sql new file mode 100644 index 0000000000..cfd5dcfc17 --- /dev/null +++ b/sql/branch.sql @@ -0,0 +1,5 @@ +BEGIN; + ALTER TABLE participants DROP COLUMN status_of_1_0_balance; + DROP TRIGGER update_status_of_1_0_balance ON participants; + DROP FUNCTION set_status_of_1_0_balance_to_resolved(); +END;