2012-11-13 52 views

回答

3

你有兩個主要選擇

a)使用的連接和Rails的執行功能

例子:

connection = ActiveRecord::Base.connection 
statement = File.read('db//data/icd_10.sql') 
connection.execute(statement) 

執行下面的SQL語句:

=> INSERT INTO `icd_10_ca_codes` (`ICD_10_CA_Code`, `Block`, `Code_id`, `Code_Description`, `Code_Includes`, `Code_Excludes`, `Code_Notes`, `created_at`, `updated_at`) 
=> VALUES ('G35', '' , 'Multiple sclerosis', 'Multiple sclerosis (of): 
• NOS 
• brain stem 
• cord 
• disseminated 
• generalized', NULL, NULL); 

b )使用seed_dump gem從SQL數據庫導出到種子文件並生成一個te mplate與數據

日提交

實施例:

$gem install seed_dump 
$rake db:seed:dump MODEL=Icd10Code APPEND=true 
$rake db:seed --trace 

生成種子文件中執行以下操作:

=> Icd10CaCode.create([ 
=> { :ICD_10_CA_Code => "G35", :Block => "G35", :Code_id => "", :Code_Description => "Multiple sclerosis", :Code_Includes => "Multiple sclerosis (of):\n• NOS\n• brain stem\n• cord\n• disseminated\n• generalized", :Code_Excludes => nil, :Code_Notes => nil, :created_at => "2013-06-24 20:37:24", :updated_at => "2013-06-24 20:37:28" }; 
=> ], :without_protection => true) 

https://github.com/rroblak/seed_dump

相關問題