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?

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
Rob@AgileConsultingLLC.com

Yeah, Rob == the man.