{"id":13483797,"url":"https://github.com/mbleigh/seed-fu","last_synced_at":"2025-05-14T03:06:42.033Z","repository":{"id":388612,"uuid":"6133","full_name":"mbleigh/seed-fu","owner":"mbleigh","description":"Advanced seed data handling for Rails, combining the best practices of several methods together.","archived":false,"fork":false,"pushed_at":"2022-08-09T06:39:24.000Z","size":170,"stargazers_count":1236,"open_issues_count":57,"forks_count":158,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-04-25T21:02:45.288Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mbleigh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2008-04-01T13:36:22.000Z","updated_at":"2025-03-26T18:54:37.000Z","dependencies_parsed_at":"2022-06-21T14:42:33.968Z","dependency_job_id":null,"html_url":"https://github.com/mbleigh/seed-fu","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbleigh%2Fseed-fu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbleigh%2Fseed-fu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbleigh%2Fseed-fu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mbleigh%2Fseed-fu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mbleigh","download_url":"https://codeload.github.com/mbleigh/seed-fu/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251556465,"owners_count":21608451,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T17:01:15.385Z","updated_at":"2025-05-14T03:06:41.999Z","avatar_url":"https://github.com/mbleigh.png","language":"Ruby","funding_links":[],"categories":["Ruby","Database Tools"],"sub_categories":[],"readme":"Seed Fu\n=======\n\nSeed 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.\n\nWarning: API Changes\n--------------------\n\nVersion 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.\n\nThe API documentation is available in full at [http://rubydoc.info/github/mbleigh/seed-fu/master/frames](http://rubydoc.info/github/mbleigh/seed-fu/master/frames).\n\nBasic Example\n-------------\n\n### In `db/fixtures/users.rb`\n\n    User.seed do |s|\n      s.id    = 1\n      s.login = \"jon\"\n      s.email = \"jon@example.com\"\n      s.name  = \"Jon\"\n    end\n\n    User.seed do |s|\n      s.id    = 2\n      s.login = \"emily\"\n      s.email = \"emily@example.com\"\n      s.name  = \"Emily\"\n    end\n\n### To load the data:\n\n    $ rake db:seed_fu\n    == Seed from /path/to/app/db/fixtures/users.rb\n     - User {:id=\u003e1, :login=\u003e\"jon\", :email=\u003e\"jon@example.com\", :name=\u003e\"Jon\"}\n     - User {:id=\u003e2, :login=\u003e\"emily\", :email=\u003e\"emily@example.com\", :name=\u003e\"Emily\"}\n\nInstallation\n------------\n\n### Rails 3.1, 3.2, 4.0, 4.1, 4.2, 5.0\n\nJust add `gem 'seed-fu', '~\u003e 2.3'` to your `Gemfile`\n\nSeed 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.\n\n### Rails 3.0\n\nThe current version is not backwards compatible with Rails 3.0. Please use `gem 'seed-fu', '~\u003e 2.0.0'`.\n\n### Rails 2.3\n\nThe current version is not backwards compatible with Rails 2.3. Please use `gem 'seed-fu', '~\u003e 1.2.0'`.\n\nConstraints\n-----------\n\nConstraints are used to identify seeds, so that they can be updated if necessary. For example:\n\n    Point.seed(:x, :y) do |s|\n      s.x = 4\n      s.y = 7\n      s.name = \"Home\"\n    end\n\nThe first time this seed is loaded, a `Point` record will be created. Now suppose the name is changed:\n\n    Point.seed(:x, :y) do |s|\n      s.x = 4\n      s.y = 7\n      s.name = \"Work\"\n    end\n\nWhen 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.\n\nIf you do not want seeds to be updated after they have been created, use `seed_once`:\n\n    Point.seed_once(:x, :y) do |s|\n      s.x = 4\n      s.y = 7\n      s.name = \"Home\"\n    end\n\nThe default constraint just checks the `id` of the record.\n\nWhere to put seed files\n-----------------------\n\nBy default, seed files are looked for in the following locations:\n\n* `#{Rails.root}/db/fixtures` and `#{Rails.root}/db/fixtures/#{Rails.env}` in a Rails app\n* `./db/fixtures` when loaded without Rails\n\nYou can change these defaults by modifying the `SeedFu.fixture_paths` array.\n\nSeed files can be named whatever you like, and are loaded in alphabetical order.\n\nTerser syntax\n-------------\n\nWhen loading lots of records, the above block-based syntax can be quite verbose. You can use the following instead:\n\n    User.seed(:id,\n      { :id =\u003e 1, :login =\u003e \"jon\",   :email =\u003e \"jon@example.com\",   :name =\u003e \"Jon\"   },\n      { :id =\u003e 2, :login =\u003e \"emily\", :email =\u003e \"emily@example.com\", :name =\u003e \"Emily\" }\n    )\n\nRake task\n---------\n\nSeed files can be run automatically using `rake db:seed_fu`. There are two options which you can pass:\n\n* `rake db:seed_fu FIXTURE_PATH=path/to/fixtures` -- Where to find the fixtures\n* `rake db:seed_fu FILTER=users,articles` -- Only run seed files with a filename matching the `FILTER`\n\nYou can also do a similar thing in your code by calling `SeedFu.seed(fixture_paths, filter)`.\n\nDisable output\n--------------\n\nTo disable output from Seed Fu, set `SeedFu.quiet = true`.\n\nHandling large seed files\n-------------------------\n\nSeed files can be huge.  To handle large files (over a million rows), try these tricks:\n\n* 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.\n* Add lines reading `# 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.\n* Load a single fixture at a time with the `FILTER` environment variable\n* If you don't need Seed Fu's ability to update seed with new data, then you may find that [activerecord-import](https://github.com/zdennis/activerecord-import) is faster\n\nGenerating seed files\n---------------------\n\nIf 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).\n\nCapistrano deployment\n---------------------\n\nSeedFu has included Capistrano [deploy script](lib/seed-fu/capistrano.rb), you just need require that\nin `config/deploy.rb`:\n\n```ruby\nrequire 'seed-fu/capistrano'\n\n# Trigger the task after update_code\nafter 'deploy:update_code', 'db:seed_fu'\n```\n\nIf you use Capistrano3, you should require another file.\n\n```ruby\nrequire 'seed-fu/capistrano3'\n\n# Trigger the task before publishing\nbefore 'deploy:publishing', 'db:seed_fu'\n```\n\nBugs / Feature requests\n-----------------------\n\nPlease report them on [Github Issues](https://github.com/mbleigh/seed-fu/issues).\n\nContributors\n------------\n\n* [Michael Bleigh](http://www.mbleigh.com/) is the original author\n* [Jon Leighton](http://jonathanleighton.com/) is the current maintainer\n* Thanks to [Matthew Beale](https://github.com/mixonic) for his great work in adding the writer, making it faster and better.\n\nCopyright © 2008-2010 Michael Bleigh, released under the MIT license\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbleigh%2Fseed-fu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmbleigh%2Fseed-fu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmbleigh%2Fseed-fu/lists"}