Seed builder for ActiveRecord. Includes seeds loader and generator.
Sponsored by Kisko Labs.
Using Bundler:
bundle add seed_builder
Using RubyGems:
gem install seed_builder
gem "seed_builder"
bin/rails db:seed
bin/rails g seed create_users
By default seed file db/seeds.rb
is loaded.
To turn off loading default seeds.rb file:
SeedBuilder.config.load_default_seeds = false
Absolute path will be resolved by using Rails.root
.
SeedBuilder.config.seeds_path = "db/seeds"
SeedBuilder.config.generate_spec = false
SeedBuilder.config.use_seed_loader = false
- User can generate seed file under
db/seeds
directory with common format - User can generate seed file with test script included
- User can run all seeds
- User can run specific seed file
- Gem patches
ActiveRecord::Tasks::DatabaseTasks.seed_loader
to have custom loader - ActiveRecord migrations generator is used to generate seed files
- Seeded data is not reversible, there is no point to implement it as logic can be complex and operations on data might lead to irreversible changes
- Seed file is not a migration, although as good practice is to keep it idempotent, e.g. by checking uniqueness of seeded records
Bug reports and pull requests are welcome on GitHub at https://github.com/amkisko/seed_builder.rb
Contribution policy:
- New features are not necessarily added to the gem
- Pull request should have test coverage for affected parts
- Pull request should have changelog entry
- It might take up to 2 calendar weeks to review and merge critical fixes
- It might take up to 6 calendar months to review and merge pull request
- It might take up to 1 calendar year to review an issue
Prefer using script usr/bin/release.sh
, it will ensure that repository is synced and after publishing gem will create a tag.
GEM_VERSION=$(grep -Eo "VERSION\s*=\s*\".+\"" lib/seed_builder.rb | grep -Eo "[0-9.]{5,}")
rm seed_builder-*.gem
gem build seed_builder.gemspec
gem push seed_builder-$GEM_VERSION.gem
git tag $GEM_VERSION && git push --tags
The gem is available as open source under the terms of the MIT License.