From e87e72b31cc46c0a816cd7876be1154e96d20e2a Mon Sep 17 00:00:00 2001 From: Changaco Date: Wed, 30 Apr 2014 17:00:16 +0200 Subject: [PATCH] make sure the transfer was actually a team take --- branch.sql | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/branch.sql b/branch.sql index 5486dce998..29dc386b3a 100644 --- a/branch.sql +++ b/branch.sql @@ -2,8 +2,23 @@ BEGIN; ALTER TABLE transfers ADD COLUMN as_team_member boolean NOT NULL DEFAULT false; - UPDATE transfers SET as_team_member = true - FROM participants WHERE participants.username = transfers.tipper - AND participants.number = 'plural'; + UPDATE transfers + SET as_team_member = true + WHERE amount <= ( + SELECT amount + FROM takes + WHERE takes.team = transfers.tipper + AND takes.member = transfers.tippee + AND takes.ctime < transfers.timestamp + ORDER BY takes.ctime DESC + LIMIT 1 + ) + AND amount != ( + SELECT amount + FROM tips + WHERE tips.ctime < transfers.timestamp + ORDER BY tips.ctime DESC + LIMIT 1 + ); END;