@@ -4,3 +4,72 @@ require 'rake'
4
4
Coderwall ::Application . load_tasks
5
5
6
6
task default : :spec
7
+
8
+
9
+ namespace :team do
10
+ task migrate : :environment do
11
+ TeamMigratorBatchJob . new . perform
12
+ end
13
+
14
+ #
15
+ # IMPORTANT: pending_join_requests is a STRING array in Postgres but an INTEGER array in MongoDB.
16
+ # IMPORTANT: pending_join_requests is an array of User#id values
17
+ #
18
+
19
+ def neq ( attr , pg , mongo , fail_if_neq = true )
20
+ left = pg . send ( attr )
21
+ right = mongo . send ( attr )
22
+
23
+ if left != right
24
+ puts "#{ attr } #{ left } != #{ right } (#{ pg . id } |#{ mongo . id } )"
25
+
26
+ if fail_if_neq
27
+ require 'pry' ; binding . pry
28
+ end
29
+ end
30
+ end
31
+
32
+ task verify : :environment do
33
+ PgTeam . find_each ( batch_size : 100 ) do |pg_team |
34
+ begin
35
+ mongo_id = pg_team . mongo_id
36
+ mongo_team = Team . find ( mongo_id )
37
+
38
+
39
+ %i( updated_at median score total slug mean pending_join_requests ) . each do |attr |
40
+ neq ( attr , pg_team , mongo_team , false )
41
+ end
42
+
43
+
44
+ %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 |
45
+ neq ( attr , pg_team , mongo_team )
46
+ end
47
+ rescue => ex
48
+
49
+ ap ex
50
+
51
+ require 'pry' ; binding . pry
52
+ end
53
+ end
54
+ end
55
+
56
+ task counts : :environment do
57
+ pg_team_count = PgTeam . count
58
+ puts "PgTeam.count=#{ pg_team_count } "
59
+ team_count = Team . count
60
+ puts "Team.count=#{ team_count } "
61
+ puts "Unmigrated teams count=#{ ( team_count - pg_team_count ) } "
62
+ end
63
+
64
+
65
+ task unmigrated : :environment do
66
+ unmigrated_teams = [ ]
67
+
68
+ Team . all . each do |team |
69
+ unmigrated_teams << team . id . to_s unless PgTeam . where ( mongo_id : team . id . to_s ) . exists?
70
+ end
71
+
72
+ puts "Unmigrated teams count=#{ unmigrated_teams . count } "
73
+ puts "Unmigrated Teams=%w(#{ unmigrated_teams . join ( ' ' ) } )"
74
+ end
75
+ end
0 commit comments