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

switch to {participant,team}_id in payment_instructions #4046

Closed
wants to merge 10 commits into from

Conversation

chadwhitacre
Copy link
Contributor

@chadwhitacre chadwhitacre commented Jun 2, 2016

Part of #835.

@chadwhitacre
Copy link
Contributor Author

Ready for review @rohitpaulk @aandis.

@chadwhitacre
Copy link
Contributor Author

@kaguillera and I used #3893 as a pattern here.

@chadwhitacre
Copy link
Contributor Author

@kaguillera and I used #3893 as a pattern here.

But we ended up doing it all in one PR instead of three. Ready for review @rohitpaulk @aandis! :-)

@chadwhitacre chadwhitacre changed the title add {participant,team}_id to payment_instructions switch to {participant,team}_id in payment_instructions Jun 2, 2016
FROM payment_instructions
ORDER BY participant_id, team_id, mtime DESC;

END;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to require some downtime on prod so that while this migration runs, no one creates a new payment_instruction or runs into error while creating them. I am not sure how big our prod payment_instructions table is, which would decide how long this migration takes. Is that an acceptable downtime @whit537 ?

Copy link
Contributor

@aandis aandis Jun 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#3864 (comment) for reference

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we club the two UPDATEs into a single UPDATE statement so that this takes lesser time?

Copy link
Contributor Author

@chadwhitacre chadwhitacre Jun 3, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to require some downtime on prod so that while this migration runs, no one creates a new payment_instruction or runs into error while creating them.

I suppose that's a reason to split this across multiple PRs.

I am not sure how big our prod payment_instructions table is, which would decide how long this migration takes.

It's small:

gratipay::MAROON=> select count(*) from payment_instructions;
┌───────┐
│ count │
├───────┤
│  3796 │
└───────┘
(1 row)

(The old tips table from Gittipay 1.0 has 82,911 records, but we're not dealing with that here.)

Testing on a local backup, I'm seeing < 2 seconds to apply branch.sql:

[gratipay] $ time psql gratipay-bak < sql/branch.sql 
Null display is "¤".
Line style is unicode.
Border style is 2.
BEGIN
ALTER TABLE
ALTER TABLE
DROP VIEW
UPDATE 3787
UPDATE 3787
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
CREATE VIEW
CREATE TRIGGER
COMMIT

real    0m1.695s
user    0m0.005s
sys     0m0.006s
[gratipay] $

Is that an acceptable downtime @whit537 ?

I could go either way. Based on the above test, it looks like the downtime is going to be very brief, but I could also see aiming for zero downtime in the interest of professional pride. :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we club the two UPDATEs into a single UPDATE statement so that this takes lesser time?

Done in 7a0c2d9, and it looks like indeed it's twice as fast (even though, for simplicity, it uses a subselect instead of a FROM):

[gratipay] $ time psql gratipay-bak < sql/branch.sql
Null display is "¤".
Line style is unicode.
Border style is 2.
BEGIN
ALTER TABLE
ALTER TABLE
DROP VIEW
UPDATE 3787
ALTER TABLE
ALTER TABLE
ALTER TABLE
ALTER TABLE
CREATE VIEW
CREATE TRIGGER
COMMIT

real    0m0.827s
user    0m0.005s
sys     0m0.005s
[gratipay] $

chadwhitacre added a commit that referenced this pull request Jun 3, 2016
@aandis
Copy link
Contributor

aandis commented Jun 6, 2016

Removed usage from some more places. Not sure if we still use some of those.

@chadwhitacre
Copy link
Contributor Author

@aandis Cool. Looks like we need some better test coverage tho. ;-)

@chadwhitacre
Copy link
Contributor Author

... because the way @kaguillera and I approached this was to make the schema change, and then fix whatever the test suite surfaced. The fact that the tests didn't surface the cases you found indicates that we have an opportunity to improve our test coverage here.

chadwhitacre added a commit that referenced this pull request Jun 8, 2016
A lack of test coverage of the bin/migrate-tips.py script surfaced
during a refactor (#4046). Therefore, we:

 - Move heavy lifting from the bin/migrate-tips.py executable into a
   migrate_all_tips function in the gratipay library for easier testing
 - Split out tip migration tests into their own test script
 - Add a few tests for migrate_all_tips
@chadwhitacre
Copy link
Contributor Author

The fact that the tests didn't surface the cases you found indicates that we have an opportunity to improve our test coverage here.

bin/migrate-tips.py coverage handled in #4049, which is against master (we'll need to rebase here once that lands).

@chadwhitacre chadwhitacre force-pushed the change-payment_instructions-foreign-key-1 branch from 5badb96 to 88525b1 Compare June 8, 2016 19:47
@chadwhitacre chadwhitacre force-pushed the change-payment_instructions-foreign-key-1 branch from 88525b1 to 38b59f1 Compare June 8, 2016 20:06
chadwhitacre added a commit that referenced this pull request Jun 8, 2016
@chadwhitacre chadwhitacre force-pushed the change-payment_instructions-foreign-key-1 branch from 0953c0d to 318a9cb Compare June 8, 2016 20:17
@chadwhitacre chadwhitacre reopened this Jun 8, 2016
@chadwhitacre
Copy link
Contributor Author

Hack close to try restarting the build. Can't see how to do it in the Travis UI. 😕

@chadwhitacre
Copy link
Contributor Author

Rebased on master to pick up #4049 and insert 355b271. Previous head was 5badb96 (though 62f6f9d includes some additional fixes caught by the tests in 355b271). Old history showing previous Travis results:

screen shot 2016-06-08 at 4 03 17 pm

@chadwhitacre
Copy link
Contributor Author

Okay! @kaguillera and I added some tests in #4049 and 355b271 to cover the additional fixes (now) in 62f6f9d. Ready for re-review here, @aandis @rohitpaulk! 😤

@chadwhitacre chadwhitacre force-pushed the change-payment_instructions-foreign-key-1 branch from 62f6f9d to f00ddfe Compare June 9, 2016 14:34
@chadwhitacre
Copy link
Contributor Author

Rebased on master. Previous head was 62f6f9d.

screen shot 2016-06-09 at 10 34 13 am

@aandis aandis force-pushed the change-payment_instructions-foreign-key-1 branch from f00ddfe to e6776c9 Compare June 11, 2016 18:15
aandis pushed a commit that referenced this pull request Jun 11, 2016
@aandis
Copy link
Contributor

aandis commented Jun 11, 2016

Rebased on master. Previous head was f00ddfe

@aandis
Copy link
Contributor

aandis commented Jun 11, 2016

Looks good to me.

@aandis
Copy link
Contributor

aandis commented Jun 11, 2016

I'll leave it to @whit537 or @rohitpaulk to merge, deploy and test this on prod in one go. Let's make sure deployment is done right. Run the migration first and then push application changes.

@rohitpaulk
Copy link
Contributor

rohitpaulk commented Jun 11, 2016

We should also turn maintenance mode on when doing this. (Our release.sh script supports this)

@whit537 - Can you have a look at Google Analytics Piwik and figure out what time of the day we usually receive the least traffic at?

@chadwhitacre
Copy link
Contributor Author

Can you have a look at Google Analytics Piwik and figure out what time of the day we usually receive the least traffic at?

Right. Soooooooo ... we don't have Piwik on right now either (gratipay/inside.gratipay.com#437). 😁

@chadwhitacre
Copy link
Contributor Author

Rebased on master. Previous head was 4f303d4.

@chadwhitacre chadwhitacre force-pushed the change-payment_instructions-foreign-key-1 branch from e6776c9 to ff40d99 Compare June 15, 2016 19:00
@chadwhitacre
Copy link
Contributor Author

chadwhitacre commented Jun 15, 2016

Alright, @kaguillera and I have digested and taken on board the desired approach of zero-downtime migrations at #3864 (comment) (and the links following). We're now planning to split this into a multi-step migration as recommended there and as implemented in #3893.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants