Skip to content

Commit aa5d18b

Browse files
committed
Updated the Avatar migration to move over the image name and set the store dir to fall back to the legacy mongo_id if it's present
1 parent 9dd9121 commit aa5d18b

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

Rakefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ namespace :team do
152152
about
153153
achievement_count
154154
analytics
155-
avatar
156155
benefit_description_1
157156
benefit_description_2
158157
benefit_description_3
@@ -210,6 +209,8 @@ namespace :team do
210209
neq(attr, pg_team_follower, mongo_team_follower, false)
211210
end
212211

212+
neq_string(:avatar, pg_team_follower, pg_team_follower.avatar.url, mongo_team_follower, mongo_team_follower.avatar.url, false)
213+
213214
%i(score size total mean median).each do |attr|
214215
neq_dec(attr, pg_team_follower, mongo_team_follower, false)
215216
end
@@ -234,6 +235,17 @@ namespace :team do
234235
print_neq_error(ex)
235236
end
236237

238+
def neq_string(attr, pg, left, mongo, right, fail_if_neq=true)
239+
if left != right
240+
puts "#{attr} | pg:#{pg.id} | mongo:#{mongo.id}| #{left} != #{right}"
241+
true
242+
else
243+
false
244+
end
245+
rescue => ex
246+
print_neq_error(ex)
247+
end
248+
237249
def neq_dec(attr, pg, mongo, fail_if_neq=true)
238250
scale = 7
239251

app/jobs/team_migrator_job.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def find_or_initialize_team(id, team)
2828

2929
begin
3030
PgTeam.find_or_initialize_by_mongo_id(id) do |pgteam|
31-
# pgteam.avatar = team.avatar
3231
pgteam.about = team.about
3332
pgteam.achievement_count = team.achievement_count
3433
pgteam.analytics = team.analytics
@@ -96,6 +95,10 @@ def find_or_initialize_team(id, team)
9695
pgteam.score = team.score.to_d.round(scale)
9796

9897
pgteam.save!
98+
99+
if team.avatar && team.avatar.file
100+
pgteam.update_column(:avatar, team.avatar.file.filename)
101+
end
99102
end
100103
rescue ActiveRecord::RecordInvalid => ex
101104
Rails.logger.error("[find_or_initialize_team(#{id}, #{team.id})] #{ex} >>\n#{ex.backtrace.join("\n ")}")

app/uploaders/team_uploader.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ class TeamUploader < CoderwallUploader
22

33
process resize_and_pad: [100, 100]
44

5+
def store_dir
6+
"/uploads/team/avatar/#{model.mongo_id || model.id}"
7+
end
8+
59
def default_url
610
ActionController::Base.helpers.asset_path 'team-avatar.png'
711
end

0 commit comments

Comments
 (0)