Skip to content

Commit 3cc59c7

Browse files
committed
missing records, making migration only add new users
1 parent efec3e6 commit 3cc59c7

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

lib/tasks/db.rake

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -155,38 +155,40 @@ namespace :db do
155155
Legacy[:users].each do |row|
156156
begin
157157
user = User.find_or_initialize_by_id(row[:id])
158-
user.attributes.keys.each do |key|
159-
user[key] = row[key.to_sym]
160-
end
158+
if user.new_record?
159+
user.attributes.keys.each do |key|
160+
user[key] = row[key.to_sym]
161+
end
161162

162-
social_links = []
163-
social_links << "[LinkedIn](#{row[:linkedin_public_url]})" unless row[:linkedin_public_url].blank?
164-
social_links << "[Blog](#{row[:blog]})" unless row[:blog].blank?
165-
social_links << "[Bitbucket](https://bitbucket.org/#{row[:bitbucket]})" unless row[:bitbucket].blank?
166-
social_links << "[Codeplex](http://www.codeplex.com/site/users/view/#{row[:codeplex]})" unless row[:codeplex].blank?
167-
social_links << "[Dribbble](http://dribbble.com/#{row[:dribbble]})" unless row[:dribbble].blank?
168-
social_links << "[StackOverflow](http://stackoverflow.com/users/#{row[:stackoverflow]})" unless row[:stackoverflow].blank?
169-
social_links << "[Speakerdeck](http://speakerdeck.com/u/#{row[:speakerdeck]})" unless row[:speakerdeck].blank?
170-
social_links << "[Slideshare](http://www.slideshare.net/#{row[:slideshare]})" unless row[:slideshare].blank?
171-
if !social_links.empty?
172-
user.about = '' if user.about.nil?
173-
user.about << "\n\n\n#{social_links.join(' ')}\n\n"
174-
end
175-
user.karma = (Legacy[:endorsements].where(endorsed_user_id: row[:id]).count + 1)
176-
user.password = SecureRandom.hex
177-
user.skills = Legacy[:skills].select(:name, :tokenized).where(
178-
deleted: false,
179-
user_id: row[:id]).collect{|row| row[:name]}
163+
social_links = []
164+
social_links << "[LinkedIn](#{row[:linkedin_public_url]})" unless row[:linkedin_public_url].blank?
165+
social_links << "[Blog](#{row[:blog]})" unless row[:blog].blank?
166+
social_links << "[Bitbucket](https://bitbucket.org/#{row[:bitbucket]})" unless row[:bitbucket].blank?
167+
social_links << "[Codeplex](http://www.codeplex.com/site/users/view/#{row[:codeplex]})" unless row[:codeplex].blank?
168+
social_links << "[Dribbble](http://dribbble.com/#{row[:dribbble]})" unless row[:dribbble].blank?
169+
social_links << "[StackOverflow](http://stackoverflow.com/users/#{row[:stackoverflow]})" unless row[:stackoverflow].blank?
170+
social_links << "[Speakerdeck](http://speakerdeck.com/u/#{row[:speakerdeck]})" unless row[:speakerdeck].blank?
171+
social_links << "[Slideshare](http://www.slideshare.net/#{row[:slideshare]})" unless row[:slideshare].blank?
172+
if !social_links.empty?
173+
user.about = '' if user.about.nil?
174+
user.about << "\n\n\n#{social_links.join(' ')}\n\n"
175+
end
176+
user.karma = (Legacy[:endorsements].where(endorsed_user_id: row[:id]).count + 1)
177+
user.password = SecureRandom.hex
178+
user.skills = Legacy[:skills].select(:name, :tokenized).where(
179+
deleted: false,
180+
user_id: row[:id]).collect{|row| row[:name]}
180181

181-
if team = Legacy[:teams].where(id: row[:team_id]).collect.first
182-
user.company = team[:name]
183-
end
182+
if team = Legacy[:teams].where(id: row[:team_id]).collect.first
183+
user.company = team[:name]
184+
end
184185

185-
if row[:banned_at].nil?
186-
Rails.logger.info "#{row[:username]} => #{row[:email]}"
187-
user.save!
188-
else
189-
Rails.logger.info "skipping banned user #{row[:username]}"
186+
if row[:banned_at].nil?
187+
Rails.logger.info "#{row[:username]} => #{row[:email]}"
188+
user.save!
189+
else
190+
Rails.logger.info "skipping banned user #{row[:username]}"
191+
end
190192
end
191193
end
192194
end

0 commit comments

Comments
 (0)