Description
Seed Fu is an attempt to once and for all solve the problem of inserting and maintaining seed data in a database. It uses a variety of techniques gathered from various places around the web and combines them to create what is hopefully the most robust seed data system around.
Seed Fu alternatives and similar gems
Based on the "Database Tools" category.
Alternatively, view Seed Fu alternatives based on common mentions on social networks and blogs.
-
Database Cleaner
Strategies for cleaning databases in Ruby. Can be used to ensure a clean state for testing. -
Lol DBA
lol_dba is a small package of rake tasks that scan your application models and displays a list of columns that probably should be indexed. Also, it can generate .sql migration scripts. -
Seedbank
Seedbank gives your seed data a little structure. Create seeds for each environment, share seeds between environments and specify dependencies to load your seeds in order. All nicely integrated with simple rake tasks. -
DatabaseConsistency
The tool to avoid various issues due to inconsistencies and inefficiencies between a database schema and application models. -
Polo
Polo travels through your database and creates sample snapshots so you can work with real world data in development. -
SchemaPlus
DISCONTINUED. SchemaPlus provides a collection of enhancements and extensions to ActiveRecord -
Upsert
Upsert on MySQL, PostgreSQL, and SQLite3. Transparently creates functions (UDF) for MySQL and PostgreSQL; on SQLite3, uses INSERT OR IGNORE. -
OnlineMigrations
Catch unsafe PostgreSQL migrations in development and run them easier in production (code helpers for table/column renaming, changing column type, adding columns with default, background migrations, etc). -
Ruby PG Extras
Ruby PostgreSQL database performance insights. Locks, index usage, buffer cache hit ratios, vacuum stats and more. -
Slack Smart Bot
Create a Slack bot that is smart and so easy to expand, create new bots on demand, run ruby code on chat, create shortcuts... The main scope of this gem is to be used internally in the company so teams can create team channels with their own bot to help them on their daily work, almost everything is suitable to be automated!! slack-smart-bot can create bots on demand, create shortcuts, run ruby code... just on a chat channel. You can access it just from your mobile phone if you want and run those tests you forgot to run, get the results, restart a server... no limits. -
PgDriveBackup
Simple solution to make encrypted with ccrypt PostgreSQL backups and storing on Google Drive API -
Perfect Shape
Perfect Shape is a collection of geometric algorithms that are mostly useful for GUI manipulation like checking containment of a point in popular geometric shapes such as rectangle, square, arc, circle, polygon, and paths containing lines, quadratic bézier curves, and cubic bezier curves. Also, some general math algorithms like IEEE-754 Remainder. -
ActiveRecord Setops
Union, Intersect, and Difference set operations for ActiveRecord (also, SQL's UnionAll). -
Rapidity
Simple but fast Redis-backed distributed rate limiter. Allows you to specify time interval and count within to limit distributed operations. -
PRY-BYETYPO 👋
A Pry plugin that captures exceptions that may arise from typos and deduces the correct command.
CodeRabbit: AI Code Reviews for Developers

* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of Seed Fu or a related project?
README
Seed Fu
Seed Fu is an attempt to once and for all solve the problem of inserting and maintaining seed data in a database. It uses a variety of techniques gathered from various places around the web and combines them to create what is hopefully the most robust seed data system around.
Warning: API Changes
Version 2.0.0 of Seed Fu introduced API changes. Seed::Writer
was been completely overhauled and will require you to update your scripts. Some other deprecations were introduced, and support is fully removed in version 2.1.0. Please see the [CHANGELOG](CHANGELOG.md) for details.
The API documentation is available in full at http://rubydoc.info/github/mbleigh/seed-fu/master/frames.
Basic Example
In db/fixtures/users.rb
User.seed do |s|
s.id = 1
s.login = "jon"
s.email = "[email protected]"
s.name = "Jon"
end
User.seed do |s|
s.id = 2
s.login = "emily"
s.email = "[email protected]"
s.name = "Emily"
end
To load the data:
$ rake db:seed_fu
== Seed from /path/to/app/db/fixtures/users.rb
- User {:id=>1, :login=>"jon", :email=>"[email protected]", :name=>"Jon"}
- User {:id=>2, :login=>"emily", :email=>"[email protected]", :name=>"Emily"}
Installation
Rails 3.1, 3.2, 4.0, 4.1, 4.2, 5.0
Just add gem 'seed-fu', '~> 2.3'
to your Gemfile
Seed Fu depends on Active Record, but doesn't have to be used with a full Rails app. Simply load and require the seed-fu
gem and you're set.
Rails 3.0
The current version is not backwards compatible with Rails 3.0. Please use gem 'seed-fu', '~> 2.0.0'
.
Rails 2.3
The current version is not backwards compatible with Rails 2.3. Please use gem 'seed-fu', '~> 1.2.0'
.
Constraints
Constraints are used to identify seeds, so that they can be updated if necessary. For example:
Point.seed(:x, :y) do |s|
s.x = 4
s.y = 7
s.name = "Home"
end
The first time this seed is loaded, a Point
record will be created. Now suppose the name is changed:
Point.seed(:x, :y) do |s|
s.x = 4
s.y = 7
s.name = "Work"
end
When this is run, Seed Fu will look for a Point
based on the :x
and :y
constraints provided. It will see that a matching Point
already exists and so update its attributes rather than create a new record.
If you do not want seeds to be updated after they have been created, use seed_once
:
Point.seed_once(:x, :y) do |s|
s.x = 4
s.y = 7
s.name = "Home"
end
The default constraint just checks the id
of the record.
Where to put seed files
By default, seed files are looked for in the following locations:
#{Rails.root}/db/fixtures
and#{Rails.root}/db/fixtures/#{Rails.env}
in a Rails app./db/fixtures
when loaded without Rails
You can change these defaults by modifying the SeedFu.fixture_paths
array.
Seed files can be named whatever you like, and are loaded in alphabetical order.
Terser syntax
When loading lots of records, the above block-based syntax can be quite verbose. You can use the following instead:
User.seed(:id,
{ :id => 1, :login => "jon", :email => "[email protected]", :name => "Jon" },
{ :id => 2, :login => "emily", :email => "[email protected]", :name => "Emily" }
)
Rake task
Seed files can be run automatically using rake db:seed_fu
. There are two options which you can pass:
rake db:seed_fu FIXTURE_PATH=path/to/fixtures
-- Where to find the fixturesrake db:seed_fu FILTER=users,articles
-- Only run seed files with a filename matching theFILTER
You can also do a similar thing in your code by calling SeedFu.seed(fixture_paths, filter)
.
Disable output
To disable output from Seed Fu, set SeedFu.quiet = true
.
Handling large seed files
Seed files can be huge. To handle large files (over a million rows), try these tricks:
- Gzip your fixtures. Seed Fu will read .rb.gz files happily.
gzip -9
gives the best compression, and with Seed Fu's repetitive syntax, a 160M file can shrink to 16M. - Add lines reading
# BREAK EVAL
in your big fixtures, and Seed Fu will avoid loading the whole file into memory. If you useSeedFu::Writer
, these breaks are built into your generated fixtures. - Load a single fixture at a time with the
FILTER
environment variable - If you don't need Seed Fu's ability to update seed with new data, then you may find that activerecord-import is faster
Generating seed files
If you need to programmatically generate seed files, for example to convert a CSV file into a seed file, then you can use [SeedFu::Writer
](lib/seed-fu/writer.rb).
Capistrano deployment
SeedFu has included Capistrano [deploy script](lib/seed-fu/capistrano.rb), you just need require that
in config/deploy.rb
:
require 'seed-fu/capistrano'
# Trigger the task after update_code
after 'deploy:update_code', 'db:seed_fu'
If you use Capistrano3, you should require another file.
require 'seed-fu/capistrano3'
# Trigger the task before publishing
before 'deploy:publishing', 'db:seed_fu'
Bugs / Feature requests
Please report them on Github Issues.
Contributors
- Michael Bleigh is the original author
- Jon Leighton is the current maintainer
- Thanks to Matthew Beale for his great work in adding the writer, making it faster and better.
Copyright © 2008-2010 Michael Bleigh, released under the MIT license
*Note that all licence references and agreements mentioned in the Seed Fu README section above
are relevant to that project's source code only.