SeedExt can truncate records and seed data from csv/yml file.
Add this line to your application's Gemfile:
gem 'seed_ext', github: rawhide/seed_ext
And then execute:
$ bundle
user1:
id: 1
name: user1
sex: 0
user2:
id: 2
name: user2
sex: 1
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.integer :sex
t.timestamps
end
end
end
class User < ActiveRecord::Base
end
User.truncation
rake db:create
rake db:migrate
rake db:seed
Users table will be truncated and be loaded data from yml file.
id,name,sex
1,user1,0
2,user2,1
User.truncation(:csv)
id,name,sex
1,user1,0
2,user2,1
User.truncation(:csv, 'db/fixures')
User.truncation!
Users table will be truncated.(supporting for sqlite3/mysql2/postgresql/sqlserver)
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request