Topic: How can create a migration file for existing data in the table

For example

I have a table Places , I had created table migration

class CreatePlace < ActiveRecord::Migration
  def change
    create_table :place do |t|
      t.string :name
      t.timestamps
    end

But this table has lot of data . How can i create a seed for this .
1.what will be the file name for that seed.

i have one seed.rb file , which contains other table data.
so how can i create new file
how can i run it



I have created  one file for crerting seed file .
But i dont know what will be the name for seed

require 'mysql2'
@client = Mysql2::Client.new(:host => "localhost", :database => "dbname", :username => "root", :password => "root")

def place_search()
  puts " Starting ....."
  query = "SELECT
    id,
    name,
    FROM places "
  results = @client.query(query)
  f = File.new("placesseeds.rb", "a")
  results.each { |r|
   f.write "Place.create(name: \"#{r['name']}\")\n"
  }
  f.close
end

place_search()




  f = File.new("placesseeds.rb", "a") --  this is the seed file name that i provide , is it correct or Not?

Last edited by saami (2012-04-26 03:28:04)