Skip to content

Commit

Permalink
Rake task to fix Authors with nil usernames
Browse files Browse the repository at this point in the history
  • Loading branch information
carols10cents committed Dec 16, 2011

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 212f242 commit 83ad212
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/tasks/fixdb.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#rake tasks to update stored data
namespace :fixdb do
desc "Set nil Author usernames"
task :set_nil_usernames => :environment do
messed_up_authors = Author.where(:username => nil)

messed_up_authors.each do |author|
user = User.where(:author_id => author.id).first
if user
if Author.count(:username => user.username) > 0
puts "Can't set username for Author #{author.id}; Author with #{user.username} already exists"
else
author.set(:username => user.username)
puts "Fixed user #{user.username}."
end
else
puts "Couldn't fix Author #{author.id}; no user found"
end
end
end
end

0 comments on commit 83ad212

Please sign in to comment.