MESSYKILL5000
2008-Jan-08 23:05 UTC
Populate a table with 100,000 values in random order via migration.. QUE?!
HOLA! I''ve got the following ruby: arr = ("0".."99999").sort{ rand(3) -1 } # shuffle-hack arr.each do | item | while item.length < 5 item.insert(0, ''0'') # puts item # Wanna see 100,000 numbers with leading zeros? end end # == EOF = I want to put all these numbers in a table, each one a new row. Is it possible to do this in a migration? I''ve been trying but I get a...> rake db:migrate...Uninitialized constant Fillkeys::Key error. (I''m putting the code in a migration, and replacing the #puts line with Key.create ( :key => item ) Comments? Suggestions? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2008-Jan-08 23:25 UTC
Re: Populate a table with 100,000 values in random order via migration.. QUE?!
On Jan 8, 2008, at 6:05 PM, MESSYKILL5000 wrote:> HOLA! I''ve got the following ruby: > > arr = ("0".."99999").sort{ rand(3) -1 } # shuffle-hackclass Fillkeys < ActiveRecord::Migration class Key < ActiveRecord::Base; end def self.up arr = (''00000''..''99999'').sort_by { rand } arr.each do |item| Key.create!(:key => item) end end end> arr.each do | item | > while item.length < 5 > item.insert(0, ''0'') > # puts item # Wanna see 100,000 numbers with leading zeros? > end > end > > # == EOF => > I want to put all these numbers in a table, each one a new row. Is it > possible to do this in a migration? I''ve been trying but I get a... > >> rake db:migrate... > Uninitialized constant Fillkeys::KeyYou do have a Key model in app/models/key.rb, right? Better is to have a minimal Key model defined right inside the migration class itself.> error. (I''m putting the code in a migration, and replacing the #puts > line with > > Key.create ( :key => item ) > > Comments? Suggestions?I hope that helps. -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
MESSYKILL5000
2008-Jan-08 23:42 UTC
Re: Populate a table with 100,000 values in random order via migration.. QUE?!
Yeah, Rob == the man. On Jan 8, 1:25 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> On Jan 8, 2008, at 6:05 PM, MESSYKILL5000 wrote: > > > HOLA! I''ve got the following ruby: > > > arr = ("0".."99999").sort{ rand(3) -1 } # shuffle-hack > > class Fillkeys < ActiveRecord::Migration > class Key < ActiveRecord::Base; end > def self.up > arr = (''00000''..''99999'').sort_by { rand } > arr.each do |item| > Key.create!(:key => item) > end > end > end > > > arr.each do | item | > > while item.length < 5 > > item.insert(0, ''0'') > > # puts item # Wanna see 100,000 numbers with leading zeros? > > end > > end > > > # == EOF => > > I want to put all these numbers in a table, each one a new row. Is it > > possible to do this in a migration? I''ve been trying but I get a... > > >> rake db:migrate... > > Uninitialized constant Fillkeys::Key > > You do have a Key model in app/models/key.rb, right? > > Better is to have a minimal Key model defined right inside the > migration class itself. > > > error. (I''m putting the code in a migration, and replacing the #puts > > line with > > > Key.create ( :key => item ) > > > Comments? Suggestions? > > I hope that helps. > > -Rob > > Rob Biedenharn http://agileconsultingllc.com > R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---