Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
make sure the transfer was actually a team take
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco committed Apr 30, 2014
1 parent c7326ca commit e87e72b
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions branch.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit e87e72b

Please sign in to comment.