@@ -4,3 +4,283 @@ require 'rake'
4
4
Coderwall ::Application . load_tasks
5
5
6
6
task default : :spec
7
+
8
+ namespace :team do
9
+ task migrate : :environment do
10
+ puts '--- Beginning team migration ---'
11
+ success = true
12
+ begin
13
+ Team . each do |team |
14
+ begin
15
+ puts ">>> Migrating #{ team . id } "
16
+ TeamMigratorJob . new . perform ( team . id . to_s )
17
+ rescue => ex
18
+ success = false
19
+ puts "[#{ team . id . to_s } ] #{ ex } >>\n #{ ex . backtrace . join ( "\n " ) } "
20
+ end
21
+ end
22
+ ensure
23
+ puts "--- #{ success ? 'Successful' : 'Unsuccessful' } team migration ---"
24
+ end
25
+ end
26
+
27
+ #
28
+ # IMPORTANT: pending_join_requests is a STRING array in Postgres but an INTEGER array in MongoDB.
29
+ # IMPORTANT: pending_join_requests is an array of User#id values
30
+ #
31
+
32
+ task verify : :environment do
33
+ #ActiveRecord::Base.logger = nil
34
+ #Mongoid.logger = nil
35
+ #Moped.logger = nil
36
+
37
+ PgTeam . find_each ( batch_size : 100 ) do |pg_team |
38
+ begin
39
+ mongo_id = pg_team . mongo_id
40
+ mongo_team = Team . find ( mongo_id )
41
+
42
+ # Ignoring:
43
+ # - updated_at
44
+
45
+ puts 'TEAM'
46
+
47
+ neq ( :slug , pg_team , mongo_team , false )
48
+
49
+ neq_string ( :pending_join_requests , pg_team , pg_team . pending_join_requests . map ( &:to_i ) . sort . join ( ', ' ) , mongo_team , mongo_team . pending_join_requests . map ( &:to_i ) . sort . join ( ', ' ) , false )
50
+
51
+ %i( score size total mean median ) . each do |attr |
52
+ neq_dec ( attr , pg_team , mongo_team , false )
53
+ end
54
+
55
+ %i( about achievement_count analytics benefit_description_1 benefit_description_2 benefit_description_3 benefit_name_1 benefit_name_2 benefit_name_3 big_image big_quote blog_feed branding country_id created_at endorsement_count facebook featured_banner_image featured_links_title github github_organization_name headline hide_from_featured highlight_tags hiring_tagline interview_steps invited_emails link_to_careers_page location monthly_subscription name number_of_jobs_to_show office_photos organization_way organization_way_name organization_way_photo our_challenge paid_job_posts premium preview_code reason_description_1 reason_description_2 reason_description_3 reason_name_1 reason_name_2 reason_name_3 size stack_list twitter upcoming_events upgraded_at valid_jobs website why_work_image your_impact youtube_url ) . each do |attr |
56
+ neq ( attr , pg_team , mongo_team )
57
+ end
58
+
59
+ # TODO: Account
60
+ if mongo_team . account . present? && pg_team . account . blank?
61
+ puts "account | pg:#{ pg_team . id } | mongo:#{ mongo_team . id } | The account was not migrated."
62
+ end
63
+
64
+ if mongo_team . account . present? && pg_team . account . present?
65
+ check_plans = %i( stripe_card_token stripe_customer_token admin_id ) . map do |attr |
66
+ neq ( attr , pg_team . account , mongo_team . account )
67
+ end . any? { |x | !x }
68
+
69
+ # TODO: Plans
70
+ if check_plans
71
+ left = pg_team . account . plans . pluck ( :id ) . sort
72
+ right = mongo_team . account . plan_ids . sort
73
+
74
+ if left != right
75
+ puts "account.plans | pg:#{ pg_team . id } | mongo:#{ mongo_team . id } | #{ left } != #{ right } "
76
+ end
77
+ end
78
+ end
79
+
80
+ #puts 'LOCATIONS'
81
+
82
+ #pg_team_locations = pg_team.locations
83
+ #mongo_team_locations = mongo_team.team_locations
84
+
85
+ #if mongo_team_locations.count != pg_team_locations.count
86
+ #puts "locations | pg:#{pg_team.id} | mongo:#{mongo_team.id}| #{mongo_team_locations.count} != #{pg_team_locations.count}"
87
+ #end
88
+
89
+ ## Ignoring:
90
+ ## - points_of_interest
91
+ #pg_team.locations.each do |pg_team_location|
92
+ #mongo_team_location = mongo_team.team_locations.select { |tl| tl.name == pg_team_location.name }.first
93
+
94
+ #%i(address city country description name state_code).each do |attr|
95
+ #neq(attr, pg_team_location, mongo_team_location, false)
96
+ #end
97
+ #end
98
+
99
+
100
+ #puts 'LINKS'
101
+
102
+ pg_team_links = pg_team . links
103
+ mongo_team_links = mongo_team . featured_links
104
+
105
+ if mongo_team_links . count != pg_team_links . count
106
+ puts "links | pg:#{ pg_team . id } | mongo:#{ mongo_team . id } | #{ mongo_team_links . count } != #{ pg_team_links . count } "
107
+ end
108
+
109
+ pg_team_links . each do |pg_team_link |
110
+ mongo_team_link = mongo_team_links . select { |tl | tl . name == pg_team_link . name } . first
111
+
112
+ %i( url name ) . each do |attr |
113
+ neq ( attr , pg_team_link , mongo_team_link , false )
114
+ end
115
+ end
116
+
117
+ #puts 'MEMBERS'
118
+
119
+ if pg_team . members . count != mongo_team . team_members . count
120
+ puts "members | pg:#{ pg_team . id } | mongo:#{ mongo_team . id } | #{ pg_team . members . count } < #{ mongo_team . team_members . count } "
121
+ end
122
+
123
+
124
+ #puts 'JOBS'
125
+
126
+ #pg_team.jobs.each do |pg_team_job|
127
+ #mongo_team_job = Team.where(id: pg_team_job.team_document_id.to_s).first
128
+
129
+ #neq(:name, pg_team_job, mongo_team_job, false)
130
+ #end
131
+
132
+ #puts 'FOLLOWERS'
133
+
134
+ pg_team . followers . each do |pg_team_follower |
135
+ mongo_team_follower = Team . where ( id : pg_team_follower . mongo_id . to_s ) . first
136
+ # admins
137
+ # editors
138
+ %i(
139
+ about
140
+ achievement_count
141
+ analytics
142
+ benefit_description_1
143
+ benefit_description_2
144
+ benefit_description_3
145
+ benefit_name_1
146
+ benefit_name_2
147
+ benefit_name_3
148
+ big_image
149
+ big_quote
150
+ blog_feed
151
+ branding
152
+ country_id
153
+ created_at
154
+ endorsement_count
155
+ facebook
156
+ featured_banner_image
157
+ featured_links_title
158
+ github_organization_name
159
+ headline
160
+ hide_from_featured
161
+ highlight_tags
162
+ hiring_tagline
163
+ interview_steps
164
+ invited_emails
165
+ link_to_careers_page
166
+ location
167
+ monthly_subscription
168
+ name
169
+ number_of_jobs_to_show
170
+ office_photos
171
+ organization_way
172
+ organization_way_name
173
+ organization_way_photo
174
+ our_challenge
175
+ paid_job_posts
176
+ premium
177
+ preview_code
178
+ reason_description_1
179
+ reason_description_2
180
+ reason_description_3
181
+ reason_name_1
182
+ reason_name_2
183
+ reason_name_3
184
+ slug
185
+ stack_list
186
+ twitter
187
+ upcoming_events
188
+ upgraded_at
189
+ valid_jobs
190
+ website
191
+ why_work_image
192
+ your_impact
193
+ youtube_url
194
+ ) . each do |attr |
195
+ neq ( attr , pg_team_follower , mongo_team_follower , false )
196
+ end
197
+ neq_string ( :pending_join_requests , pg_team_follower , pg_team_follower . pending_join_requests . map ( &:to_i ) . sort . join ( ', ' ) , mongo_team_follower , mongo_team_follower . pending_join_requests . map ( &:to_i ) . sort . join ( ', ' ) , false )
198
+
199
+ neq_string ( :avatar , pg_team_follower , pg_team_follower . avatar . url , mongo_team_follower , mongo_team_follower . avatar . url , false )
200
+
201
+ %i( score size total mean median ) . each do |attr |
202
+ neq_dec ( attr , pg_team_follower , mongo_team_follower , false )
203
+ end
204
+ end
205
+
206
+ # TODO: Pending Requests
207
+ end
208
+ end
209
+ end
210
+
211
+ def neq ( attr , pg , mongo , fail_if_neq = true )
212
+ left = pg . send ( attr )
213
+ right = mongo . send ( attr )
214
+
215
+ if left != right
216
+ puts "#{ attr } | pg:#{ pg . id } | mongo:#{ mongo . id } | #{ left } != #{ right } "
217
+ true
218
+ else
219
+ false
220
+ end
221
+ rescue => ex
222
+ print_neq_error ( ex )
223
+ end
224
+
225
+ def neq_string ( attr , pg , left , mongo , right , fail_if_neq = true )
226
+ if left != right
227
+ puts "#{ attr } | pg:#{ pg . id } | mongo:#{ mongo . id } | #{ left } != #{ right } "
228
+ true
229
+ else
230
+ false
231
+ end
232
+ rescue => ex
233
+ print_neq_error ( ex )
234
+ end
235
+
236
+ def neq_dec ( attr , pg , mongo , fail_if_neq = true )
237
+ scale = 7
238
+
239
+ left = pg . send ( attr ) . to_d . round ( scale )
240
+ right = mongo . send ( attr ) . to_d . round ( scale )
241
+
242
+
243
+ if left != right
244
+ puts "#{ attr } | pg:#{ pg . id } | mongo:#{ mongo . id } | #{ left } != #{ right } "
245
+ true
246
+ else
247
+ false
248
+ end
249
+ rescue => ex
250
+ print_neq_error ( ex )
251
+ end
252
+
253
+ def print_neq_error ( ex )
254
+ puts '*' *80
255
+ puts
256
+ puts ex
257
+ puts
258
+ puts '-' *80
259
+ puts
260
+ ap ex . backtrace
261
+ puts
262
+ puts '*' *80
263
+
264
+ require 'pry' ; binding . pry
265
+ end
266
+
267
+ task counts : :environment do
268
+ pg_team_count = PgTeam . count
269
+ puts "PgTeam.count=#{ pg_team_count } "
270
+ team_count = Team . count
271
+ puts "Team.count=#{ team_count } "
272
+ puts "Unmigrated teams count=#{ ( team_count - pg_team_count ) } "
273
+ end
274
+
275
+
276
+ task unmigrated : :environment do
277
+ unmigrated_teams = [ ]
278
+
279
+ Team . all . each do |team |
280
+ unmigrated_teams << team . id . to_s unless PgTeam . where ( mongo_id : team . id . to_s ) . exists?
281
+ end
282
+
283
+ puts "Unmigrated teams count=#{ unmigrated_teams . count } "
284
+ puts "Unmigrated Teams=%w(#{ unmigrated_teams . join ( ' ' ) } )"
285
+ end
286
+ end
0 commit comments