Skip to content

Instantly share code, notes, and snippets.

@edwardloveall
Created January 21, 2019 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwardloveall/11d56af9beeada461235c291223d6d9e to your computer and use it in GitHub Desktop.
Save edwardloveall/11d56af9beeada461235c291223d6d9e to your computer and use it in GitHub Desktop.
class GenerateUsernamesForUsers::V20190120141952 < LuckyRecord::Migrator::Migration::V1
class TempUser < BaseModel
table :users do
column email : String
column username : String?
end
end
def migrate
TempUser::BaseQuery.all.each do |user|
new_username = user.email.split("@").first
TempUser::BaseForm.update!(user, username: new_username)
puts "Generated username #{new_username} for #{user.email}"
end
end
def rollback
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment