Created
March 31, 2012 17:28
-
-
Save maxwell/2266934 to your computer and use it in GitHub Desktop.
a start on a migration rake task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # columns to drop from use | |
| # invitation_token, invitation_sent_at, invitation_service, invitation_identifier, invitation_limit | |
| #TLDR FLOW | |
| # 1. Create LegacyInvitaions Table (migration) | |
| # 2. Run this rake? task to create a boatload of data about all invitations in history of the system | |
| # 3. Delete all users with nil usernames | |
| # 4. Change code to use LegacyInvitations | |
| # 5. Purge code of old Invitation model, DROP invitation table, and remove columns from user | |
| # 6. dance | |
| unaccepted_users = User.where("username IS NULL") | |
| old_failed_facebook_invited = unaccepted_users.where(:invitation_service => 'facebook') | |
| new_failed_facebook_invited = unaccepted_users.where('email is null).where('invitation_service is null') | |
| #scenarios | |
| # old invites | |
| # if the person was invited a long time ago, they have on their user object, invitation_identifiers, and invitation_service | |
| # these people do not have invitation objects | |
| # newer invites | |
| #these people have invite objects, but in the email field | |
| #and they have invite objects | |
| #However, invite objects themselves lose their meaning if their user object with the invite token is gone, #as it is the join which is looked up when a user clicks on an old invitation link :( | |
| #info we need | |
| #LegacyInvite (email - token - who invited(user_id)) | |
| Invitation.where(:service => 'facebook').delete_all | |
| unaccepted_users.select(:id, :email, :invitation_identifier, :invitation_service, :invitation_token).find_in_batchs do |users| | |
| users.each do |user| | |
| email = '' | |
| token = '' | |
| inviter_id = '' | |
| #old style | |
| if user.invitation_service == 'email' | |
| email = user.invitation_identifier | |
| invited_by_id = user.invited_by_id | |
| elsif user.email.present? | |
| email = user.email | |
| inviter_id = Invitation.where(:service => 'email', :identifier => 'email').sender_id | |
| else #we have no email, this is a failed facebook invite. | |
| inviter_id = Invitation.where(:service => 'facebook', :identifier => user.invitation_identifer).sender_id | |
| end | |
| token = user.invitation_token | |
| LegacyInvitation.create(:token => token, :email => email, :invited_by_id => inviter_id) | |
| end | |
| end | |
| #facebook invites are a lost cause | |
| old_failed_facebook_invited.delete_all | |
| new_failed_facebook_invited.delete_all | |
| #User.where("username IS NULL").delete_all | |
| #DROP INVITATIONS table | |
| #to do.... COMPLETELY REMOVE OLD INVITATION FLOW... change lookup on legacy invitation controller to go thru new table to access new invite code.. should not be that bad |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment