Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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.
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 for details.
The API documentation is available in full at http://rubydoc.info/github/mbleigh/seed-fu/master/frames.
db/fixtures/users.rb
User.seed do |s|
s.id = 1
s.login = "jon"
s.email = "jon@example.com"
s.name = "Jon"
end
User.seed do |s|
s.id = 2
s.login = "emily"
s.email = "emily@example.com"
s.name = "Emily"
end
$ rake db:seed_fu
== Seed from /path/to/app/db/fixtures/users.rb
- User {:id=>1, :login=>"jon", :email=>"jon@example.com", :name=>"Jon"}
- User {:id=>2, :login=>"emily", :email=>"emily@example.com", :name=>"Emily"}
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.
The current version is not backwards compatible with Rails 3.0. Please use gem 'seed-fu', '~> 2.0.0'
.
The current version is not backwards compatible with Rails 2.3. Please use gem 'seed-fu', '~> 1.2.0'
.
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.
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 RailsYou 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.
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 => "jon@example.com", :name => "Jon" },
{ :id => 2, :login => "emily", :email => "emily@example.com", :name => "Emily" }
)
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 the FILTER
You can also do a similar thing in your code by calling SeedFu.seed(fixture_paths, filter)
.
To disable output from Seed Fu, set SeedFu.quiet = true
.
Seed files can be huge. To handle large files (over a million rows), try these tricks:
gzip -9
gives the best compression, and with Seed Fu's repetitive syntax, a 160M file can shrink to 16M.# BREAK EVAL
in your big fixtures, and Seed Fu will avoid loading the whole file into memory. If you use SeedFu::Writer
, these breaks are built into your generated fixtures.FILTER
environment variableIf you need to programmatically generate seed files, for example to convert a CSV file into a seed file, then you can use SeedFu::Writer
.
SeedFu has included Capistrano deploy script, 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'
Please report them on Github Issues.
Copyright © 2008-2010 Michael Bleigh, released under the MIT license
FAQs
Unknown package
We found that discourse-seed-fu demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.