Skip to content

Commit 6cbe13b

Browse files
committed
Tweaked the precision on the calculated scores for conversion from MongoDB => Postgres
1 parent d6cbe74 commit 6cbe13b

File tree

9 files changed

+216
-83
lines changed

9 files changed

+216
-83
lines changed

Gemfile.lock

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
GIT
2-
remote: https://github.com/rebelidealist/stripe-ruby-mock
3-
revision: f4229cbe762bc2a5a302cdd83088c283881e9c5a
4-
branch: live-tests
2+
remote: git://github.com/emberjs/ember-rails.git
3+
revision: 5e5a398f3c67c3a3b84b7513b93b22bf81055cc9
54
specs:
6-
stripe-ruby-mock (1.10.1.7)
7-
dante (>= 0.2.0)
8-
jimson-temp
9-
stripe (>= 1.15.0)
5+
ember-rails (0.15.0)
6+
active_model_serializers
7+
barber (>= 0.4.1)
8+
ember-data-source (>= 1.0.0.beta.5)
9+
ember-source (>= 1.1.0)
10+
execjs (>= 1.2)
11+
handlebars-source (> 1.0.0)
12+
jquery-rails (>= 1.0.17)
13+
railties (>= 3.1)
1014

1115
GIT
1216
remote: git://github.com/emberjs/ember-rails.git
@@ -44,18 +48,14 @@ GIT
4448
rest-client (~> 1.4)
4549

4650
GIT
47-
remote: git://github.com/emberjs/ember-rails.git
48-
revision: 5e5a398f3c67c3a3b84b7513b93b22bf81055cc9
51+
remote: https://github.com/rebelidealist/stripe-ruby-mock
52+
revision: f4229cbe762bc2a5a302cdd83088c283881e9c5a
53+
branch: live-tests
4954
specs:
50-
ember-rails (0.15.0)
51-
active_model_serializers
52-
barber (>= 0.4.1)
53-
ember-data-source (>= 1.0.0.beta.5)
54-
ember-source (>= 1.1.0)
55-
execjs (>= 1.2)
56-
handlebars-source (> 1.0.0)
57-
jquery-rails (>= 1.0.17)
58-
railties (>= 3.1)
55+
stripe-ruby-mock (1.10.1.7)
56+
dante (>= 0.2.0)
57+
jimson-temp
58+
stripe (>= 1.15.0)
5959

6060
GEM
6161
remote: https://rubygems.org/

Rakefile

Lines changed: 128 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,21 @@ task default: :spec
88

99
namespace :team do
1010
task migrate: :environment do
11-
TeamMigratorBatchJob.new.perform
11+
puts '--- Beginning team migration ---'
12+
success = true
13+
begin
14+
Team.each do |team|
15+
begin
16+
puts ">>> Migrating #{team.id}"
17+
TeamMigratorJob.new.perform(team.id.to_s)
18+
rescue => ex
19+
success = false
20+
puts "[#{team.id.to_s}] #{ex} >>\n#{ex.backtrace.join("\n ")}"
21+
end
22+
end
23+
ensure
24+
puts "--- #{success ? 'Successful' : 'Unsuccessful'} team migration ---"
25+
end
1226
end
1327

1428
#
@@ -40,6 +54,32 @@ namespace :team do
4054
require 'pry'; binding.pry
4155
end
4256

57+
def neq_dec(attr, pg, mongo, fail_if_neq=true)
58+
scale = 7
59+
left = pg.send(attr).to_d.round(scale)
60+
right = mongo.send(attr).to_d.round(scale)
61+
62+
63+
if left != right
64+
puts "#{attr} | pg:#{pg.id} | mongo:#{mongo.id}| #{left} != #{right}"
65+
true
66+
else
67+
false
68+
end
69+
rescue => ex
70+
puts '*'*80
71+
puts
72+
puts ex
73+
puts
74+
puts '-'*80
75+
puts
76+
ap ex.backtrace
77+
puts
78+
puts '*'*80
79+
80+
require 'pry'; binding.pry
81+
end
82+
4383
task verify: :environment do
4484
PgTeam.find_each(batch_size: 100) do |pg_team|
4585
begin
@@ -49,14 +89,18 @@ namespace :team do
4989
# Ignoring:
5090
# - updated_at
5191

52-
puts '----------------------------------------------------------------------------------------------------'
53-
puts 'TEAM'
54-
puts '----------------------------------------------------------------------------------------------------'
92+
#puts '----------------------------------------------------------------------------------------------------'
93+
#puts 'TEAM'
94+
#puts '----------------------------------------------------------------------------------------------------'
5595

56-
%i(median score total slug mean pending_join_requests).each do |attr|
96+
%i(slug pending_join_requests).each do |attr|
5797
neq(attr, pg_team, mongo_team, false)
5898
end
5999

100+
%i(score size total mean median).each do |attr|
101+
neq_dec(attr, pg_team, mongo_team, false)
102+
end
103+
60104
%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|
61105
neq(attr, pg_team, mongo_team)
62106
end
@@ -83,9 +127,9 @@ namespace :team do
83127
end
84128

85129

86-
puts '----------------------------------------------------------------------------------------------------'
87-
puts 'LOCATIONS'
88-
puts '----------------------------------------------------------------------------------------------------'
130+
#puts '----------------------------------------------------------------------------------------------------'
131+
#puts 'LOCATIONS'
132+
#puts '----------------------------------------------------------------------------------------------------'
89133

90134
pg_team_locations = pg_team.locations
91135
mongo_team_locations = mongo_team.team_locations
@@ -105,9 +149,9 @@ namespace :team do
105149
end
106150

107151

108-
puts '----------------------------------------------------------------------------------------------------'
109-
puts 'LINKS'
110-
puts '----------------------------------------------------------------------------------------------------'
152+
#puts '----------------------------------------------------------------------------------------------------'
153+
#puts 'LINKS'
154+
#puts '----------------------------------------------------------------------------------------------------'
111155

112156
pg_team_links = pg_team.links
113157
mongo_team_links = mongo_team.featured_links
@@ -124,38 +168,101 @@ namespace :team do
124168
end
125169
end
126170

127-
puts '----------------------------------------------------------------------------------------------------'
128-
puts 'MEMBERS'
129-
puts '----------------------------------------------------------------------------------------------------'
171+
#puts '----------------------------------------------------------------------------------------------------'
172+
#puts 'MEMBERS'
173+
#puts '----------------------------------------------------------------------------------------------------'
130174

131175
if pg_team.members.count != mongo_team.team_members.count
132176
puts "members | pg:#{pg_team.id} | mongo:#{mongo_team.id}| #{mongo_team.team_members.count} != #{pg_team.members.count}"
133177
end
134178

135179

136-
puts '----------------------------------------------------------------------------------------------------'
137-
puts 'JOBS'
138-
puts '----------------------------------------------------------------------------------------------------'
180+
#puts '----------------------------------------------------------------------------------------------------'
181+
#puts 'JOBS'
182+
#puts '----------------------------------------------------------------------------------------------------'
139183

140184
pg_team.jobs.each do |pg_team_job|
141185
mongo_team_job = Team.where(id: pg_team_job.team_document_id.to_s).first
142186

143187
neq(:name, pg_team_job, mongo_team_job, false)
144188
end
145189

146-
puts '----------------------------------------------------------------------------------------------------'
147-
puts 'FOLLOWERS'
148-
puts '----------------------------------------------------------------------------------------------------'
190+
#puts '----------------------------------------------------------------------------------------------------'
191+
#puts 'FOLLOWERS'
192+
#puts '----------------------------------------------------------------------------------------------------'
149193

150194
pg_team.followers.each do |pg_team_follower|
151195
mongo_team_follower = Team.where(id: pg_team_follower.mongo_id.to_s).first
152196
# admins
153197
# editors
154-
%i(about achievement_count analytics avatar 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_organization_name headline hide_from_featured highlight_tags hiring_tagline interview_steps invited_emails link_to_careers_page location mean median monthly_subscription name number_of_jobs_to_show office_photos organization_way organization_way_name organization_way_photo our_challenge paid_job_posts pending_join_requests premium preview_code reason_description_1 reason_description_2 reason_description_3 reason_name_1 reason_name_2 reason_name_3 score size slug stack_list total twitter upcoming_events updated_at upgraded_at valid_jobs website why_work_image your_impact youtube_url).each do |attr|
198+
%i(
199+
about
200+
achievement_count
201+
analytics
202+
avatar
203+
benefit_description_1
204+
benefit_description_2
205+
benefit_description_3
206+
benefit_name_1
207+
benefit_name_2
208+
benefit_name_3
209+
big_image
210+
big_quote
211+
blog_feed
212+
branding
213+
country_id
214+
created_at
215+
endorsement_count
216+
facebook
217+
featured_banner_image
218+
featured_links_title
219+
github_organization_name
220+
headline
221+
hide_from_featured
222+
highlight_tags
223+
hiring_tagline
224+
interview_steps
225+
invited_emails
226+
link_to_careers_page
227+
location
228+
monthly_subscription
229+
name
230+
number_of_jobs_to_show
231+
office_photos
232+
organization_way
233+
organization_way_name
234+
organization_way_photo
235+
our_challenge
236+
paid_job_posts
237+
pending_join_requests
238+
premium
239+
preview_code
240+
reason_description_1
241+
reason_description_2
242+
reason_description_3
243+
reason_name_1
244+
reason_name_2
245+
reason_name_3
246+
slug
247+
stack_list
248+
twitter
249+
upcoming_events
250+
upgraded_at
251+
valid_jobs
252+
website
253+
why_work_image
254+
your_impact
255+
youtube_url
256+
).each do |attr|
155257
neq(attr, pg_team_follower, mongo_team_follower, false)
156258
end
259+
260+
%i(score size total mean median).each do |attr|
261+
neq_dec(attr, pg_team_follower, mongo_team_follower, false)
262+
end
157263
end
158264

265+
159266
# TODO: Pending Requests
160267
end
161268
end

app/jobs/team_migrator_job.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ def find_or_initialize_team(id, team)
5858
pgteam.invited_emails = team.invited_emails
5959
pgteam.link_to_careers_page = team.link_to_careers_page
6060
pgteam.location = team.location
61-
pgteam.mean = team.mean
62-
pgteam.median = team.median
6361
pgteam.monthly_subscription = team.monthly_subscription
6462
pgteam.name = team.name
6563
pgteam.number_of_jobs_to_show = team.number_of_jobs_to_show
@@ -78,11 +76,9 @@ def find_or_initialize_team(id, team)
7876
pgteam.reason_name_1 = team.reason_name_1
7977
pgteam.reason_name_2 = team.reason_name_2
8078
pgteam.reason_name_3 = team.reason_name_3
81-
pgteam.score = team.score
8279
pgteam.size = team.size
8380
pgteam.slug = team.slug
8481
pgteam.stack_list = team.stack_list
85-
pgteam.total = team.total
8682
pgteam.twitter = team.twitter
8783
pgteam.upcoming_events = team.upcoming_events
8884
pgteam.updated_at = team.updated_at
@@ -93,6 +89,12 @@ def find_or_initialize_team(id, team)
9389
pgteam.your_impact = team.your_impact
9490
pgteam.youtube_url = team.youtube_url
9591

92+
scale = 8
93+
pgteam.mean = team.mean.to_d.round(scale)
94+
pgteam.total = team.total.to_d.round(scale)
95+
pgteam.median = team.median.to_d.round(scale)
96+
pgteam.score = team.score.to_d.round(scale)
97+
9698
pgteam.save!
9799
end
98100
rescue ActiveRecord::RecordInvalid => ex

config/database.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ default: &default
44
host: localhost
55
password:
66
pool: 5
7-
port: <%= ENV['DEV_POSTGRES_PORT'] || 5432 %>
7+
port: 5432
88
username: vagrant
99

1010
development:

config/mongoid.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
development:
22
sessions:
33
default:
4-
database: badgify_development
4+
database: heroku_app2303161
55
hosts:
66
- localhost:27017
77

88
test:
99
sessions:
1010
default:
11-
database: badgify_test
11+
database: heroku_app2303161
1212
hosts:
1313
- localhost:27017
1414

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
class FixTypesOnPgTeams < ActiveRecord::Migration
22
def change
3-
change_column(:teams, :mean, :float, default: 0.0)
4-
change_column(:teams, :median, :float, default: 0.0)
5-
change_column(:teams, :score, :float, default: 0.0)
6-
change_column(:teams, :total, :float, default: 0.0)
3+
change_column(:teams, :mean, :decimal, precision: 40, scale: 30, default: 0.0)
4+
change_column(:teams, :median, :decimal, precision: 40, scale: 30, default: 0.0)
5+
change_column(:teams, :score, :decimal, precision: 40, scale: 30, default: 0.0)
6+
change_column(:teams, :total, :decimal, precision: 40, scale: 30, default: 0.0)
77
end
88
end

0 commit comments

Comments
 (0)