Skip to content

Commit 9359392

Browse files
committed
working on porting new data
1 parent 99c17ad commit 9359392

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
/tmp
1414
.env
1515
public/uploads
16+
TODO

lib/tasks/db.rake

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -150,43 +150,46 @@ namespace :db do
150150
Badge.reset_pk_sequence
151151
end
152152

153+
def port_data_since
154+
["created_at > ? OR updated_at > ?", 2.day.ago, 2.day.ago]
155+
end
156+
153157
task :users => :connect do
154158
User.reset_pk_sequence
155-
Legacy[:users].each do |row|
159+
Legacy[:users].where(port_since).each do |row|
156160
begin
157161
user = User.find_or_initialize_by_id(row[:id])
158-
if user.new_record?
159-
user.attributes.keys.each do |key|
160-
user[key] = row[key.to_sym]
161-
end
162-
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]}
181-
182-
if team = Legacy[:teams].where(id: row[:team_id]).collect.first
183-
user.company = team[:name]
184-
end
185-
186-
187-
Rails.logger.info "#{row[:username]} => #{row[:email]}"
188-
user.save!
162+
user.attributes.keys.each do |key|
163+
user[key] = row[key.to_sym]
164+
end
165+
166+
social_links = []
167+
social_links << "[LinkedIn](#{row[:linkedin_public_url]})" unless row[:linkedin_public_url].blank?
168+
social_links << "[Blog](#{row[:blog]})" unless row[:blog].blank?
169+
social_links << "[Bitbucket](https://bitbucket.org/#{row[:bitbucket]})" unless row[:bitbucket].blank?
170+
social_links << "[Codeplex](http://www.codeplex.com/site/users/view/#{row[:codeplex]})" unless row[:codeplex].blank?
171+
social_links << "[Dribbble](http://dribbble.com/#{row[:dribbble]})" unless row[:dribbble].blank?
172+
social_links << "[StackOverflow](http://stackoverflow.com/users/#{row[:stackoverflow]})" unless row[:stackoverflow].blank?
173+
social_links << "[Speakerdeck](http://speakerdeck.com/u/#{row[:speakerdeck]})" unless row[:speakerdeck].blank?
174+
social_links << "[Slideshare](http://www.slideshare.net/#{row[:slideshare]})" unless row[:slideshare].blank?
175+
if !social_links.empty?
176+
user.about = '' if user.about.nil?
177+
user.about << "\n\n\n#{social_links.join(' ')}\n\n"
178+
end
179+
user.karma = (Legacy[:endorsements].where(endorsed_user_id: row[:id]).count + 1)
180+
user.password = SecureRandom.hex
181+
user.skills = Legacy[:skills].select(:name, :tokenized).where(
182+
deleted: false,
183+
user_id: row[:id]).collect{|row| row[:name]}
184+
185+
if team = Legacy[:teams].where(id: row[:team_id]).collect.first
186+
user.company = team[:name]
189187
end
188+
189+
190+
Rails.logger.info "#{row[:username]} => #{row[:email]}"
191+
user.save!
192+
190193
end
191194
end
192195
User.reset_pk_sequence
@@ -216,7 +219,6 @@ namespace :db do
216219
end
217220
Protip.reset_pk_sequence
218221
end
219-
220222
end
221223

222224
# rails r 'puts Badges.all.each{|b| puts "\"#{b.name}\" => [\"#{b.display_name}\", \"#{b.image_path.gsub("badges/", "")}\", \"#{b.description}\", \"#{b.for}\"]," }'

0 commit comments

Comments
 (0)