Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
Databasebeginner

Seed Data Generator

Share

Generate database seed/sample data

Works with OpenClaude

You are a database developer building seed data generators. The user wants to create realistic sample data for database tables to populate development and testing environments.

What to check first

  • Run npm list to verify you have a database driver installed (e.g., mysql2, pg, sqlite3, mongodb)
  • Confirm your database connection string or credentials are available in .env or config files
  • Check that your target database exists and you have write permissions

Steps

  1. Install a seed data library like faker (generates realistic fake data) with npm install @faker-js/faker
  2. Create a seeds or seeders directory in your project root to organize seed files
  3. Import your database connection module and the Faker library at the top of your seed script
  4. Define a main seeding function that connects to the database and creates sample records
  5. Use Faker methods like faker.person.name(), faker.internet.email(), faker.location.city() to generate realistic values
  6. Loop to insert multiple records with INSERT statements or ORM methods (e.g., .create() in Sequelize)
  7. Add error handling with try-catch blocks and log success/failure messages
  8. Execute the seed file with node seeds/seedDatabase.js or add it as an npm script in package.json

Code

const { faker } = require('@faker-js/faker');
const mysql = require('mysql2/promise');
require('dotenv').config();

const pool = mysql.createPool({
  host: process.env.DB_HOST,
  user: process.env.DB_USER,
  password: process.env.DB_PASSWORD,
  database: process.env.DB_NAME,
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0,
});

async function seedUsers(count = 50) {
  const connection = await pool.getConnection();
  try {
    console.log(`Seeding ${count} users...`);
    
    for (let i = 0; i < count; i++) {
      const firstName = faker.person.firstName();
      const lastName = faker.person.lastName();
      const email = faker.internet.email({ firstName, lastName });
      const phone = faker.phone.number();
      const createdAt = faker.date.past({ years: 2 });

      const query = 'INSERT INTO users (first_name, last_name, email, phone, created_at) VALUES (?, ?, ?, ?, ?)';
      await connection.execute(query, [firstName, lastName, email, phone, createdAt]);
    }
    
    console.log(`✓ Successfully seeded ${count} users`);
  } catch (error) {
    console.error('Error seeding users:', error.message);
    throw error;
  } finally {
    connection.release();
  }
}

async function seedProducts(count = 30) {

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

CategoryDatabase
Difficultybeginner
Version1.0.0
AuthorClaude Skills Hub
databaseseeddata

Install command:

curl -o ~/.claude/skills/seed-data-generator.md https://claude-skills-hub.vercel.app/skills/database/seed-data-generator.md

Related Database Skills

Other Claude Code skills in the same category — free to download.

Want a Database skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.