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

Commit

Permalink
Drop payment_instructions.{participant,team}
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Jun 16, 2016
1 parent 4c6577e commit 0bd4c14
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
7 changes: 3 additions & 4 deletions gratipay/models/participant/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,21 +839,20 @@ def set_payment_instruction(self, team, amount, update_self=True, update_team=Tr
NEW_PAYMENT_INSTRUCTION = """\
INSERT INTO payment_instructions
(ctime, participant, participant_id, team, team_id, amount)
(ctime, participant_id, team_id, amount)
VALUES ( COALESCE (( SELECT ctime
FROM payment_instructions
WHERE ( participant_id=%(participant_id)s
AND team_id=%(team_id)s
)
LIMIT 1
), CURRENT_TIMESTAMP)
, %(participant)s, %(participant_id)s, %(team)s, %(team_id)s, %(amount)s
, %(participant_id)s, %(team_id)s, %(amount)s
)
RETURNING *
"""
args = dict(participant=self.username, participant_id=self.id, team=team.slug,
team_id=team.id, amount=amount)
args = dict(participant_id=self.id, team_id=team.id, amount=amount)
t = (cursor or self.db).one(NEW_PAYMENT_INSTRUCTION, args)
t_dict = t._asdict()

Expand Down
7 changes: 2 additions & 5 deletions gratipay/models/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,10 @@ def migrate_tips(self):
WITH rows AS (
INSERT INTO payment_instructions
(ctime, mtime, participant, participant_id, team, team_id, amount,
is_funded)
(ctime, mtime, participant_id, team_id, amount, is_funded)
SELECT ct.ctime
, ct.mtime
, ct.tipper
, (SELECT id FROM participants WHERE username=ct.tipper)
, %(slug)s
, %(team_id)s
, ct.amount
, ct.is_funded
Expand All @@ -348,7 +345,7 @@ def migrate_tips(self):
RETURNING 1
) SELECT count(*) FROM rows;
""", {'slug': self.slug, 'team_id': self.id, 'owner': self.owner})
""", {'team_id': self.id, 'owner': self.owner})


# Images
Expand Down
2 changes: 0 additions & 2 deletions gratipay/utils/fake_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ def fake_payment_instruction(db, participant, team):
, "payment_instructions"
, ctime=faker.date_time_this_year()
, mtime=faker.date_time_this_month()
, participant=participant.username
, participant_id=participant.id
, team=team.slug
, team_id=team.id
, amount=fake_tip_amount()
)
Expand Down
8 changes: 8 additions & 0 deletions sql/branch.sql
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@ BEGIN; -- Step 2
FOR EACH ROW EXECUTE PROCEDURE update_payment_instruction();

END;


BEGIN; -- Step 3

ALTER TABLE payment_instructions DROP COLUMN participant;
ALTER TABLE payment_instructions DROP COLUMN team;

END;
4 changes: 0 additions & 4 deletions tests/py/test_tip_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,10 @@ def test_mt_migrates_tips_to_payment_instructions(self):
payment_instructions = self.db.all("SELECT * FROM payment_instructions "
"ORDER BY participant_id ASC")
assert len(payment_instructions) == 2
assert payment_instructions[0].participant == 'alice'
assert payment_instructions[0].participant_id == self.alice.id
assert payment_instructions[0].team == 'new_team'
assert payment_instructions[0].team_id == self.new_team.id
assert payment_instructions[0].amount == 1
assert payment_instructions[1].participant == 'bob'
assert payment_instructions[1].participant_id == self.bob.id
assert payment_instructions[1].team == 'new_team'
assert payment_instructions[1].team_id == self.new_team.id
assert payment_instructions[1].amount == 2

Expand Down

0 comments on commit 0bd4c14

Please sign in to comment.