README.md in seed_dump-3.2.0 vs README.md in seed_dump-3.2.1
- old
+ new
@@ -34,22 +34,22 @@
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"}
+ {password: "123456", username: "test_1"},
+ {password: "234567", username: "test_2"}
])
Dump only data from the users table and dump a maximum of 1 record:
$ rake db:seed:dump MODELS=User LIMIT=1
Result:
User.create!([
- {id: 1, password: "123456", username: "test_1"}
+ {password: "123456", username: "test_1"}
])
Append to `db/seeds.rb` instead of overwriting it:
rake db:seed:dump APPEND=true
@@ -68,12 +68,12 @@
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"}
+ {password: "123456", username: "test_1"},
+ {password: "234567", username: "test_2"}
])
Write the dump to a file:
irb(main):002:0> SeedDump.dump(User, file: 'db/seeds.rb')
@@ -86,24 +86,32 @@
irb(main):004:0> SeedDump.dump(User, exclude: [:name, :age])
Options are specified as a Hash for the second argument.
+In the console, any relation of ActiveRecord rows can be dumped (not individual objects though)
+
+ irb(main):001:0> puts SeedDump.dump(User.where(is_admin: false)
+ User.create!([
+ {password: "123456", username: "test_1", is_admin: false},
+ {password: "234567", username: "test_2", is_admin: false}
+ ])
+
+
Options
-------
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`.
`batch_size`: Controls the number of records that are written to file at a given time. Default: 1000. If you're running out of memory when dumping, try decreasing this. If things are dumping too slow, trying increasing this.
-`exclude`: Attributes to be excluded from the dump. By default `id`, `created_at`, and `updated_at` are excluded. Pass a comma-separated list to the Rake task (i.e. `name,age`) and an array on the console (i.e. `[:name, :age]`).
+`exclude`: Attributes to be excluded from the dump.Pass a comma-separated list to the Rake task (i.e. `name,age`) and an array on the console (i.e. `[:name, :age]`). Default: `[:id, :created_at, :updated_at]` (this default can be overridden by just setting this option)
`file`: Write to the specified output file. The Rake task default is `db/seeds.rb`. The console returns the dump as a string by default.
`import`: If `true`, output will be in the format needed by the [activerecord-import](https://github.com/zdennis/activerecord-import) gem, rather than the default format. Default: `false`.
`limit`: Dump no more than 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))`).
`model[s]`: Restrict the dump to the specified comma-separated list of models. Default: all models. If you are using a Rails engine you can dump a specific model by passing "EngineName::ModelName". Rake task only. Example: `rake db:seed:dump MODELS="User, Position, Function"`
-