Importing a large sql file directly into mysql via a rails migration
or otherwise running a sql file through the mysql commandline client, with the current connection details:
class CreateZipCodes < ActiveRecord::Migration
def self.up
#Loading that large of a YAML file can cause problems
zip_code_file = File.expand_path(File.join(File.dirname(FILE), “..”, “zip_codes.sql”))
config = ActiveRecord::Base.connection.instance_variable_get(‘@config’)
`mysql -u#{config[:username]} -p#{config[:password]} #{config[:database]} < #{zip_code_file}`
end def self.down drop_table :zip_codes endend