https://github.com/wheeyls/custom_seeds
https://github.com/wheeyls/custom_seeds
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/wheeyls/custom_seeds
- Owner: wheeyls
- Created: 2024-10-07T21:12:25.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2024-11-20T15:53:36.000Z (6 months ago)
- Last Synced: 2024-11-20T16:41:27.225Z (6 months ago)
- Language: Ruby
- Homepage:
- Size: 10.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CustomSeeds
Seed file helpers for Rails applications.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'custom_seeds'
```And then execute:
$ bundle
## Usage
Create a seedfile under `db/seeds`:
```ruby
# db/seeds/users/followed_products.rbCustomSeeds.define do
title 'Followed Products'
description 'Add followed products to user accounts'let(:products) { Product.validated.sample }
before do
FollowedProduct.destroy_all
endrecords do
User.all
endeach_record do |user|
products.each do { |product| user.followed_products.create!(product: product) }
endlog_each do |user|
"User #{user.email} followed #{user.followed_products.count} products"
end
end
```### CLI
Run seeds using the `rseed` command:
$ rseed
$ rseed db/seeds/users/
$ rseed db/seeds/users/followed_products.rb
$ rseed db/seeds/users/followed_products.rb --dry-run
$ rseed db/seeds/users/followed_products.rb --verboseRun all seeds:
### Rake
Run the file using the rake task:
```bash
$ rake db:seed:users:followed_products
```Run all seeds using the rake task:
```bash
$ rake db:seed:all
```