mcpField
S
seed-database

seed-database

github.com/igmarinData & databases2839 installsUpdated 4w ago
Repository

About seed-database

A Rails development skill for preparing seed data and test scenarios. It covers repeatable, environment-scoped seeds, FactoryBot usage, credential safety, and verification steps.

Key features

  1. 01Create repeatable seeds with find_or_create_by!
  2. 02Scope non-production data by environment
  3. 03Use FactoryBot for test scenarios
  4. 04Avoid hardcoded credentials
  5. 05Verify seeds with Rails commands

Use cases

  1. 01Add static reference records to a Rails app
  2. 02Set up test data with factories
  3. 03Seed development data without affecting production
  4. 04Check that repeated seed runs create no duplicates

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/igmarin/rails-agent-skills --skill seed-database

After installing, type/seed-databasein Claude Code to confirm it loaded.

Bundled filesEXAMPLES.mdreferences/workflow.md

Details

From the project README

Seed Database

Manage development and test data effectively.

Quick Reference

UseSolution
Static reference datadb/seeds.rb with find_or_create_by!
Test scenariosFactoryBot in spec/factories/
Complex relationshipsBoth combined

HARD-GATE

NEVER commit production data to seeds
ALWAYS use factories for test-specific scenarios
ALWAYS make seeds idempotent (can run multiple times safely)
NEVER hardcode credentials (passwords, API keys, secrets) in seeds, factories, or examples
  - Use ENV variables (e.g., ENV.fetch('DEFAULT_SEED_PASSWORD')) or SecureRandom.hex(16) for non-production data
  - Use `rails credentials:edit` to manage production secrets, never commit them in code

Core Process

  1. Write idempotent seeds — use find_or_create_by! so re-runs are safe.
  2. Scope by environment — guard non-production data with Rails.env checks.
  3. Run seeds — execute rails db:seed (or rails db:setup for a fresh database).
  4. Validate idempotency — run rails db:seed a second time and confirm no duplicates or errors.
  5. Verify data — open rails console and spot-check expected records exist with correct attributes.

Minimal Inline Example

A copy-paste ready db/seeds.rb covering idempotency, environment scoping, and safe credentials:

# db/seeds.rb

# Static reference data — safe to run repeatedly
Role.find_or_create_by!(name: 'admin') do |r|
  r.description = 'Full system access'
end

Role.find_or_create_by!(name: 'member') do |r|
  r.description = 'Standard user access'
end

# Development-only seed data — never runs in production
if Rails.env.development?
  User.find_or_create_by!(email: '[email protected]') do |u|
    u.role       = Role.find_by!(name: 'admin')
    u.password   = ENV.fetch('DEFAULT_SEED_PASSWORD', SecureRandom.hex(16))
  end
end

For FactoryBot factory definitions and more complex relationship patterns, see EXAMPLES.md.

Extended Resources (Progressive Disclosure)

Load these files only when their specific content is needed:

  • EXAMPLES.md — Use when you need complete seeding examples with environment-specific patterns and FactoryBot factory definitions
  • references/workflow.md — Use when implementing complex seeding workflows or migration-dependent seed data

Output Style

  1. Use idiomatic Rails seeding patterns.
  2. Structure factories clearly.
  3. Follow the credential and idempotency rules in HARD-GATE without exception.
  4. Include verification commands: rails db:seed, a second idempotency run, and a rails console spot-check.
  5. Language — Must be in English unless explicitly requested otherwise.

Integration

SkillWhen to chain
write-testsWhen setting up test scenarios
review-migrationWhen ensuring DB schema is aligned

Comments

Markdown supported