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

Commit

Permalink
implement takes
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed May 11, 2016
1 parent fbdb0b3 commit a012015
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion gratipay/models/team/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from aspen import json, log
from gratipay.exceptions import InvalidTeamName
from gratipay.models import add_event
from gratipay.models.team import mixins
from postgres.orm import Model

from gratipay.billing.exchanges import MINIMUM_CHARGE
Expand All @@ -30,7 +31,7 @@ def slugize(name):
return slug


class Team(Model):
class Team(Model, mixins.Takes):
"""Represent a Gratipay team.
"""

Expand Down
36 changes: 36 additions & 0 deletions sql/branch.sql
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,39 @@ BEGIN;
DROP VIEW current_payroll;
DROP TABLE payroll;
END;


-- https://github.com/gratipay/gratipay.com/pull/4023

BEGIN;

-- takes - how participants express membership in teams
CREATE TABLE takes
( id bigserial PRIMARY KEY
, ctime timestamp with time zone NOT NULL
, mtime timestamp with time zone NOT NULL DEFAULT now()
, participant_id bigint NOT NULL REFERENCES participants(id)
, team_id bigint NOT NULL REFERENCES teams(id)
, ntakes int NOT NULL
, recorder_id bigint NOT NULL REFERENCES participants(id)
, CONSTRAINT not_negative CHECK (ntakes >= 0)
);

CREATE VIEW memberships AS
SELECT * FROM (
SELECT DISTINCT ON (participant_id, team_id) t.*
FROM takes t
JOIN participants p ON p.id = t.participant_id
WHERE p.is_suspicious IS NOT TRUE
ORDER BY participant_id
, team_id
, mtime DESC
) AS anon WHERE ntakes > 0;

ALTER TABLE teams ADD COLUMN ntakes int default 0;
ALTER TABLE teams ADD COLUMN ntakes_unclaimed int default 0;
ALTER TABLE teams ADD COLUMN ntakes_claimed int default 0;
ALTER TABLE teams ADD CONSTRAINT ntakes_sign CHECK (ntakes >= 0);
ALTER TABLE teams ADD CONSTRAINT ntakes_sum CHECK (ntakes = ntakes_claimed + ntakes_unclaimed);

END;

0 comments on commit a012015

Please sign in to comment.