README.md in seed_dump-2.0.0 vs README.md in seed_dump-3.0.0
- old
+ new
@@ -1,81 +1,97 @@
Seed Dump
========
Seed Dump is a Rails 4 plugin that adds a rake task named `db:seed:dump`.
-It allows you to create a `db/seeds.rb` from the existing data in your database.
+It allows you to create seed data files from the existing data in your database.
+You can also use Seed Dump from the Rails console. See below for usage examples.
+
Note: if you want to use Seed Dump with Rails 3 or earlier, use [version 0.5.3](http://rubygems.org/gems/seed_dump/versions/0.5.3).
-Example Usage
--------------
+Installation
+------------
+Add it to your Gemfile with:
+
+ gem 'seed_dump'
+
+Or install it by hand:
+
+ $ gem install seed_dump
+
+Examples
+--------
+
+### Rake task
+
Dump all data directly to `db/seeds.rb`:
$ rake db:seed:dump
-Dump only data from the users and products table and dump a maximum amount of 2 records:
+Result:
- $ rake db:seed:dump MODELS=User,Product LIMIT=2
+ Product.create!([
+ {category_id: 1, description: "Long Sleeve Shirt", name: "Long Sleeve Shirt"},
+ {category_id: 3, description: "Plain White Tee Shirt", name: "Plain T-Shirt"}
+ ])
+ User.create!([
+ {id: 1, password: "123456", username: "test_1"},
+ {id: 2, password: "234567", username: "test_2"}
+ ])
-Result:
+Dump only data from the users table and dump a maximum amount of 1 record:
- $ cat db/seeds.rb
- # Autogenerated by the db:seed:dump task
- # Do not hesitate to tweak this to your needs
+ $ rake db:seed:dump MODELS=User,Product LIMIT=1
- products = Product.create!([
- { :category_id => 1, :description => "Long Sleeve Shirt", :name => "Long Sleeve Shirt" },
- { :category_id => 3, :description => "Plain White Tee Shirt", :name => "Plain T-Shirt" }
- ])
+Result:
- users = User.create!([
- { :id => 1, :password => "123456", :username => "test_1" },
- { :id => 2, :password => "234567", :username => "tes2" }
+ User.create!([
+ {id: 1, password: "123456", username: "test_1"}
])
Append to `db/seeds.rb` instead of overwriting it:
rake db:seed:dump APPEND=true
Use another output file instead of `db/seeds.rb`:
- rake db:seed:dump FILE=db/categories.rb
+ rake db:seed:dump FILE=db/seeds/users.rb
-If you want the dump to use `create` rather than `create!`:
+There are more options that can be set— see below for all of them.
- rake db:seed:dump CREATE_METHOD='create'
+### Console
-There are more environment variables that can be set— see below for all of them.
+Output a dump of all User records:
+ irb(main):001:0> puts SeedDump.dump(User)
+ User.create!([
+ {id: 1, password: "123456", username: "test_1"},
+ {id: 2, password: "234567", username: "test_2"}
+ ])
-Installation
-------------
+Write the dump to a file:
-Add it to your Gemfile with:
+ irb(main):002:0> SeedDump.dump(User, file: 'db/seeds.rb')
- gem 'seed_dump'
+Append the dump to a file:
-Or install it by hand:
+ irb(main):003:0> puts SeedDump.dump(User, file: 'db/seeds.rb', append: true)
- $ gem install seed_dump
+Options are specified as a Hash to the second argument.
+Options
+-------
-All environment variables
--------------------------
+Options are common to both the Rake task and the console, except where noted.
-`APPEND`: If set to `true`, append the data to the file instead of overwriting it. Default: `false`.
+`append`: If set to `true`, append the data to the file instead of overwriting it. Default: `false`.
-`CREATE_METHOD`: Use the specified create method rather than `create!` (the default).
+`exclude`: Attributes to be excluded from the dump. Default: `id, created_at, updated_at`.
-`FILE`: Use a different output file. Default: `db/seeds.rb`.
+`file`: Write to the specified output file. Default in Rake task is `db/seeds.rb`. Console returns the dump as a string by default.
-`LIMIT`: Dump no more then this amount of data. Default: no limit.
+`limit`: Dump no more then this amount of data. Default: no limit. Rake task only. In the console just pass in an ActiveRecord::Relation with the appropriate limit (e.g. `SeedDump.dump(User.limit(5))`).
-`MAX`: Split one create action per model into several create actions with MAX elements in each. Default: no limit. Useful for large data dumping to reduce memory usage.
+`model[s]`: Restrict the dump to the specified comma-separated list of models. Default: all models. Rake task only.
-`MODEL[S]`: A model name or a comma-separated list of models. Default: all models.
-
-`WITH_ID`: If set to `true`, include the `:id` in the `create` options. Default: `false`.
-
-`TIMESTAMPS`: If set to `true`, include the `:created_by` and `:updated_by` timestamps. Default: `true`.