Germinate
A Rails plugin for seeding the database with initial application data.
Install / Use
/learn @tylerhunt/GerminateREADME
Germinate
Seeds are like migrations, but for your data. They makes it easy to populate the database of a Rails application with default data.
There are three methods by which seed data may be generated: create, update, and create_or_update. Each of these works by specifying a key that's used to identify a record. In the case of create the key will be used to ensure that the record doesn't already exist in the database. For update and create_or_update it's used to locate the record to be updated.
Keys are specified as method calls, with values being passed to the methods as arguments. For an ID of 1, use id(1). For a state and abbreviation, use state_and_abbreviation('FL', 'Florida').
Additional attributes may be chained on to the end as a hash of key/value pairs passed to the attributes method.
Example
class TierSeed < Germinate::Seed
create by name
create do |tier| tier.name('Ultra') end
update by ID and name
update do |tier| tier.id_and_name(1, 'Basic') end
create or update by ID
create_or_update do |tier| tier.id(1).attributes(:name => 'Standard') tier.id(2).attributes(:name => 'Premium') end end
Rake Task
To seed the database, use the included rake task.
rake db:seed
Generator
There's also a generator called that can be used to generate seed stubs. The following will generate a seed for the User model with an entry for a user with a username of "admin."
./script/generator seed User username:admin
Copyright (c) 2008 Tyler Hunt, released under the MIT license
Related Skills
feishu-drive
354.3k|
things-mac
354.3kManage Things 3 via the `things` CLI on macOS (add/update projects+todos via URL scheme; read/search/list from the local Things database)
clawhub
354.3kUse the ClawHub CLI to search, install, update, and publish agent skills from clawhub.com
Metodologias_causa_raiz
Agente de IA Consultor em Balanced Scorecard com arquitetura RAG otimizada (LangGraph + Redis + Cohere)
