Permalink
Browse files

Add TABLES param to db:seed:dump task

  • Loading branch information...
1 parent 7b4cd2f commit 8021a74b074265a8032a2bcd193de4383b6badc3 @ivannovosad committed Sep 4, 2013
Showing with 7 additions and 2 deletions.
  1. +7 −2 lib/tasks/seed_dumper.rake
@@ -1,9 +1,14 @@
namespace :db do
namespace :seed do
- desc 'Dump records from the database into db/seeds.rb'
+ desc 'Dump records from the database into db/seeds.rb (param TABLES e.g.: TABLES=people,roles)'
task :dump => :environment do
+
+ all_tables = ActiveRecord::Base.connection.tables
+ tables = ENV['TABLES'].split(",") if ENV['TABLES'].present?
+ tables_to_dump = all_tables && (tables.nil? ? all_tables : tables)
+
Dir.glob(Rails.root + '/app/models/*.rb').each { |file| require file }
- models = Rails::VERSION::MAJOR >= 3 ? ActiveRecord::Base.connection.tables.map {|t| t.classify.constantize rescue nil}.compact : Object.subclasses_of(ActiveRecord::Base)
+ models = Rails::VERSION::MAJOR >= 3 ? tables_to_dump.map {|t| t.classify.constantize rescue nil}.compact : Object.subclasses_of(ActiveRecord::Base)
models.each { |model| SeedDumper::Writer.write_data(model.name, SeedDumper::Fetcher.fetch_data(model) ) }
end

0 comments on commit 8021a74

Please sign in to comment.