Claude Skills Guide

Claude Code Database Seeding Automation

Database seeding is a critical part of development workflows, yet it remains repetitive and error-prone. Claude Code offers powerful ways to automate seeding through its skill system, allowing you to generate seed files, manage test data, and maintain consistency across environments. This guide covers practical approaches to database seeding automation using Claude Code skills.

Understanding Claude Skills for Database Tasks

Claude Code skills are Markdown files stored in ~/.claude/skills/ that customize Claude’s behavior during sessions. Several skills help with database-related tasks:

To use a skill, simply type its slash command in your Claude Code session:

/sql-mcp
/tdd

Skills can be combined. Activate /sql-mcp to connect to your database, then use /tdd to generate appropriate test data for your schema.

Creating Seed Files with Claude

When starting a new project, generate seed files by describing your schema to Claude. Suppose you have a PostgreSQL database with users, products, and orders tables:

-- schema.sql
CREATE TABLE users (
  id SERIAL PRIMARY KEY,
  email VARCHAR(255) UNIQUE NOT NULL,
  name VARCHAR(255) NOT NULL,
  created_at TIMESTAMP DEFAULT NOW()
);

CREATE TABLE products (
  id SERIAL PRIMARY KEY,
  name VARCHAR(255) NOT NULL,
  price DECIMAL(10,2) NOT NULL,
  stock INTEGER DEFAULT 0
);

CREATE TABLE orders (
  id SERIAL PRIMARY KEY,
  user_id INTEGER REFERENCES users(id),
  product_id INTEGER REFERENCES products(id),
  quantity INTEGER NOT NULL,
  total DECIMAL(10,2) NOT NULL,
  created_at TIMESTAMP DEFAULT NOW()
);

Activate /sql-mcp and ask Claude to generate seed data:

Generate seed data for this schema. Create 10 users with realistic names and emails, 5 products with varied prices, and 20 orders with random user-product combinations.

Claude produces a seed file like this:

-- seeds.sql
-- Users
INSERT INTO users (email, name) VALUES
('john.doe@example.com', 'John Doe'),
('jane.smith@example.com', 'Jane Smith'),
('bob.wilson@example.com', 'Bob Wilson'),
('alice.johnson@example.com', 'Alice Johnson'),
('charlie.brown@example.com', 'Charlie Brown'),
('diana.prince@example.com', 'Diana Prince'),
('edward.norton@example.com', 'Edward Norton'),
('fiona.apple@example.com', 'Fiona Apple'),
('george.martin@example.com', 'George Martin'),
('hannah.montana@example.com', 'Hannah Montana');

-- Products
INSERT INTO products (name, price, stock) VALUES
('Wireless Mouse', 29.99, 100),
('Mechanical Keyboard', 89.99, 50),
('USB-C Hub', 45.00, 75),
('Monitor Stand', 34.50, 30),
('Webcam HD', 59.99, 60);

-- Orders (sample)
INSERT INTO orders (user_id, product_id, quantity, total) VALUES
(1, 1, 2, 59.98),
(2, 3, 1, 45.00),
(3, 2, 1, 89.99),
(1, 4, 1, 34.50),
(4, 5, 1, 59.99);

Automating Seed Generation with Scripts

For repeatable seeding, create a Claude skill that generates seeds on demand. Store this as ~/.claude/skills/seed-gen.md:

# Seed Generation Skill

When asked to generate database seeds:
1. Analyze the provided schema or existing table structures
2. Generate realistic test data that respects foreign key constraints
3. Include edge cases: null values, boundary conditions, duplicate scenarios
4. Output SQL, JSON, or CSV depending on project requirements

For SQL output, use appropriate syntax for PostgreSQL, MySQL, or SQLite based on project config.

With this skill active, describe your needs:

/seed-gen
Generate 1000 user records with unique emails, random creation dates within the last year, and profile data in JSON format

Claude produces bulk seed data efficiently. For JSON output:

[
  {
    "email": "user001@example.com",
    "name": "User One",
    "created_at": "2025-04-15T10:30:00Z",
    "profile": {"age": 28, "country": "US", "verified": true}
  },
  {
    "email": "user002@example.com", 
    "name": "User Two",
    "created_at": "2025-05-22T14:45:00Z",
    "profile": {"age": 34, "country": "UK", "verified": false}
  }
]

Seeding Different Database Types

Claude adapts to various database systems. Here are patterns for common databases:

PostgreSQL

-- Use generate_series for bulk data
INSERT INTO users (email, name, created_at)
SELECT 
  'user' || i || '@example.com',
  'User ' || i,
  NOW() - INTERVAL '1 day' * random() * 365
FROM generate_series(1, 1000) AS i;

MongoDB

For MongoDB with the sql-mcp skill or native driver:

// seed-mongodb.js
db.users.insertMany(
  Array.from({length: 100}, (_, i) => ({
    email: `user${i}@example.com`,
    name: `User ${i}`,
    createdAt: new Date(Date.now() - Math.random() * 31536000000),
    settings: { notifications: Math.random() > 0.5 }
  }))
);

SQLite

-- SQLite seeding with transactions
BEGIN TRANSACTION;
INSERT INTO products (name, price, stock) VALUES 
  ('Product A', 19.99, 50),
  ('Product B', 29.99, 30),
  ('Product C', 39.99, 20);
COMMIT;

Integrating with Project Workflows

Combine seeding with other Claude skills for complete workflow automation:

  1. Use /frontend-design to scaffold a new project with database models, then /seed-gen to create initial data
  2. Use /tdd to validate that your seeding logic produces valid relationships
  3. Use /supermemory to remember your project’s preferred seed patterns—so Claude consistently generates data matching your conventions

Example workflow:

/frontend-design
Create a Node.js Express API with user and order models

/seed-gen
Generate seed data for both models with 50 users and 200 orders

/tdd
Write tests that verify the order total calculation works correctly

Seeding Best Practices

Follow these practices for maintainable seed files:

-- Factory pattern in SQL
CREATE FUNCTION make_user(email_prefix TEXT) RETURNS void AS $$
BEGIN
  INSERT INTO users (email, name) VALUES 
    (email_prefix || '@example.com', 'Test ' || initcap(email_prefix));
END;
$$ LANGUAGE plpgsql;

-- Usage
SELECT make_user('alice');
SELECT make_user('bob');

CI/CD Integration

Seed your test database in CI pipelines:

# .github/workflows/test.yml
name: Test with Seeded Database

jobs:
  test:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:16
        env:
          POSTGRES_PASSWORD: test
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
    
    steps:
      - uses: actions/checkout@v4
      
      - name: Run schema and seeds
        run: |
          psql -h localhost -U postgres -d testdb -f schema.sql
          psql -h localhost -U postgres -d testdb -f seeds.sql
      
      - name: Run tests
        run: npm test

Conclusion

Claude Code transforms database seeding from manual work into an automated process. By creating reusable skills, generating appropriate test data, and integrating with your existing tooling, you maintain consistent development environments and accelerate iteration cycles. The combination of /sql-mcp, /tdd, /supermemory, and custom seed generation skills provides a complete solution for managing database state in any project.


Built by theluckystrike — More at zovo.one