Skip to main content
skill CX Codex

data-seeding-fixtures-builder — Claude Code skill: setup guide

data-seeding-fixtures-builder builds deterministic mock data, factory functions, realistic fixtures, and database reset scripts for testing environments.

MIT 265 installs ★ 64 updated 2026-01-12

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add patricio0312rev/skills --skill data-seeding-fixtures-builder -a claude-code
Open on GitHub

What data-seeding-fixtures-builder does

This skill equips coding assistants with blueprints for TypeScript seed workflows using Prisma ORM and @faker-js/faker. It structures test data generation around entity factory classes such as UserFactory and OrderFactory, supporting single records, bulk generation, and relation handling.

Presets are split across distinct environments. Test suites get small predictable records through pinned faker.seed() values, staging receives bulk entities, and local development keeps minimal sets. It also outlines a database truncation script using raw SQL commands.

The database reset script directly relies on PostgreSQL syntax, executing session_replication_role overrides to bypass foreign key constraints during table truncation.

What it helps with

  • generate predictable seed records with fixed Faker seeds
  • create entity factory classes for related database models
  • prepare static product fixtures for Playwright integration tests
  • write a database reset script using PostgreSQL table truncation

Example prompts for the agent

  • Generate Prisma seed factories for users and orders with Faker
  • Create a PostgreSQL database reset script using TRUNCATE CASCADE
  • Set up deterministic test fixtures with a fixed faker seed

How to install data-seeding-fixtures-builder

1Skills CLI (Vercel)

npx skills add patricio0312rev/skills --skill data-seeding-fixtures-builder -a claude-code

2Manually: put the files in place

~/.claude/skills/data-seeding-fixtures-builder/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/data-seeding-fixtures-builder/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about data-seeding-fixtures-builder

How to install data-seeding-fixtures-builder in Claude Code?

Run npx skills add patricio0312rev/skills --skill data-seeding-fixtures-builder -a claude-code in your project terminal.

What does data-seeding-fixtures-builder do?

It guides your assistant in writing deterministic seeds, entity factories, environment-specific configs, and cleanup scripts using Prisma and Faker.

Can the reset script run on any database?

No, the bundled reset script specifically requires PostgreSQL because it reads pg_tables and sets session_replication_role.

Source text

SKILL.md · MIT
---
name: data-seeding-fixtures-builder
description: Generates deterministic seed data for development and testing with factory functions, realistic fixtures, and database reset scripts. Use for "data seeding", "test fixtures", "database seeding", or "mock data generation".
---

# Data Seeding & Fixtures Builder

Generate realistic, deterministic seed data for development and testing.

## Seed Data Strategy

```typescript
// prisma/seed.ts
import { PrismaClient } from "@prisma/client";
import { faker } from "@faker-js/faker";

const prisma = new PrismaClient();

async function main() {
  console.log("🌱 Seeding database...");

  // Clear existing data
  await prisma.order.deleteMany();
  await prisma.user.deleteMany();

  // Seed users
  const users = await seedUsers(10);
  console.log(`✅ Created ${users.length} users`);

  // Seed orders
  const orders = await seedOrders(users, 50);
  console.log(`✅ Created ${orders.length} orders`);

  console.log("✅ Seeding complete!");
}

main()
  .catch((e) => {
    console.error(e);
    process.exit(1);
  })
  .finally(async () => {
    await prisma.$disconnect();
  });
```

## Factory Functions

```typescript
// factories/user.factory.ts
import { faker } from "@faker-js/faker";
import { PrismaClient, User } from "@prisma/client";

const prisma = new PrismaClient();

export interface UserFactoryOptions {
  email?: string;
  name?: string;
  role?: "USER" | "ADMIN";
}

export class UserFactory {
  static async create(options: UserFactoryOptions = {}): Promise<User> {
    return prisma.user.create({
      data: {
        email: options.email || faker.internet.email(),
        name: options.name || faker.person.fullName(),
        role: options.role || "USER",
        createdAt: faker.date.past(),
      },
    });
  }

  static async createMany(
    count: number,
    options: UserFactoryOptions = {}
  ): Promise<User[]> {
    return Promise.all(
      Array.from({ length: count }, () => this.create(options))
    );
  }

  static async createAdmin(): Promise<User> {
    return this.create({ role: "ADMIN" });
  }
}

// Usage:
// const user = await UserFactory.create();
// const admin = await UserFactory.createAdmin();
// const users = await UserFactory.createMany(10);
```

## Realistic Fixtures

```typescript
// fixtures/products.ts
import { Product } from "@prisma/client";

export const PRODUCT_FIXTURES: Omit<
  Product,
  "id" | "createdAt" | "updatedAt"
>[] = [
  {
    name: 'MacBook Pro 16"',
    description: "Powerful laptop for developers",
    price: 2499.99,
    stock: 50,
    category: "Electronics",
  },
  {
    name: "iPhone 15 Pro",
    description: "Latest flagship smartphone",
    price: 999.99,
    stock: 100,
    category: "Electronics",
  },
  {
    name: "AirPods Pro",
    description: "Wireless earbuds with noise cancellation",
    price: 249.99,
    stock: 200,
    category: "Electronics",
  },
];

// Seed products
async function seedProducts() {
  return Promise.all(
    PRODUCT_FIXTURES.map((product) => prisma.product.create({ data: product }))
  );
}
```

## Deterministic Seeding

```typescript
// Use fixed seed for reproducibility
import { faker } from "@faker-js/faker";

// Set seed for deterministic data
faker.seed(12345);

// Same data every time
const user1 = {
  email: faker.internet.email(), // Always same email
  name: faker.person.fullName(), // Always same name
};

// Reset for different test
faker.seed(67890);
```

## Relationship Building

```typescript
// factories/order.factory.ts
export class OrderFactory {
  static async create(userId: number): Promise<Order> {
    const products = await prisma.product.findMany({ take: 3 });

    const order = await prisma.order.create({
      data: {
        userId,
        status: faker.helpers.arrayElement(["pending", "paid", "shipped"]),
        total: faker.number.float({ min: 10, max: 1000, precision: 0.01 }),
      },
    });

    // Create order items
    await Promise.all(
      products.map((product) =>
        prisma.orderItem.create({
          data: {
            orderId: order.id,
            productId: product.id,
            quantity: faker.number.int({ min: 1, max: 5 }),
            price: product.price,
          },
        })
      )
    );

    return order;
  }

  static async createForUser(user: User, count: number): Promise<Order[]> {
    return Promise.all(
      Array.from({ length: count }, () => this.create(user.id))
    );
  }
}
```

## Environment-Specific Seeds

```typescript
// seeds/development.ts
export async function seedDevelopment() {
  // Development: Few records, easy to debug
  const users = await UserFactory.createMany(5);
  const products = await ProductFactory.createMany(10);

  for (const user of users) {
    await OrderFactory.createForUser(user, 2);
  }
}

// seeds/staging.ts
export async function seedStaging() {
  // Staging: Moderate data, realistic scenarios
  const users = await UserFactory.createMany(50);
  const products = await ProductFactory.createMany(100);

  for (const user of users) {
    await OrderFactory.createForUser(
      user,
      faker.number.int({ min: 1, max: 10 })
    );
  }
}

// seeds/testing.ts
export async function seedTesting() {
  // Testing: Minimal, predictable data
  faker.seed(12345); // Deterministic

  const user = await UserFactory.create({
    email: "[email protected]",
    name: "Test User",
  });

  const product = await ProductFactory.create({
    name: "Test Product",
    price: 99.99,
  });

  return { user, product };
}

// Main seed file
async function main() {
  const env = process.env.NODE_ENV;

  if (env === "development") {
    await seedDevelopment();
  } else if (env === "staging") {
    await seedStaging();
  } else if (env === "test") {
    await seedTesting();
  }
}
```

## Database Reset Script

```typescript
// scripts/reset-db.ts
import { PrismaClient } from "@prisma/client";

const prisma = new PrismaClient();

async function resetDatabase() {
  console.log("🗑️  Resetting database...");

  // Disable foreign key checks (PostgreSQL)
  await prisma.$executeRaw`SET session_replication_role = 'replica';`;

  // Get all tables
  const tables = await prisma.$queryRaw<{ tablename: string }[]>`
    SELECT tablename FROM pg_tables WHERE schemaname = 'public';
  `;

  // Truncate all tables
  for (const { tablename } of tables) {
    if (tablename !== "_prisma_migrations") {
      await prisma.$executeRawUnsafe(`TRUNCATE TABLE "${tablename}" CASCADE;`);
      console.log(`  Truncated ${tablename}`);
    }
  }

  // Re-enable foreign key checks
  await prisma.$executeRaw`SET session_replication_role = 'origin';`;

  console.log("✅ Database reset complete");
}

resetDatabase()
  .catch((e) => {
    console.error(e);
    process.exit(1);
  })
  .finally(() => prisma.$disconnect());
```

## Test Fixtures for E2E Tests

```typescript
// tests/fixtures/e2e.fixture.ts
import { test as base } from "@playwright/test";
import { UserFactory, ProductFactory } from "../factories";

type Fixtures = {
  authenticatedUser: User;
  products: Product[];
};

export const test = base.extend<Fixtures>({
  authenticatedUser: async ({ page }, use) => {
    // Create user
    const user = await UserFactory.create();

    // Login
    await page.goto("/login");
    await page.fill('[name="email"]', user.email);
    await page.fill('[name="password"]', "password123");
    await page.click('button[type="submit"]');

    await use(user);

    // Cleanup
    await prisma.user.delete({ where: { id: user.id } });
  },

  products: async ({}, use) => {
    const products = await ProductFactory.createMany(5);
    await use(products);

    // Cleanup
    await prisma.product.deleteMany({
      where: { id: { in: products.map((p) => p.id) } },
    });
  },
});

// Usage:
test("should add product to cart", async ({ authenticatedUser, products }) => {
  // Test with pre-seeded data
});
```

## Package.json Scripts

```json
{
  "scripts": {
    "db:seed": "tsx prisma/seed.ts",
    "db:seed:dev": "NODE_ENV=development tsx prisma/seed.ts",
    "db:seed:staging": "NODE_ENV=staging tsx prisma/seed.ts",
    "db:reset": "tsx scripts/reset-db.ts && npm run db:seed",
    "db:reset:test": "tsx scripts/reset-db.ts && NODE_ENV=test tsx prisma/seed.ts"
  }
}
```

## Best Practices

1. **Use factories**: Reusable data generation
2. **Deterministic in tests**: Fixed seed values
3. **Realistic fixtures**: Production-like data
4. **Environment-specific**: Different needs per environment
5. **Cleanup after tests**: Avoid pollution
6. **Relationship integrity**: Proper foreign keys
7. **Performance**: Batch inserts for large datasets

## Output Checklist

- [ ] Seed script created
- [ ] Factory functions for each model
- [ ] Realistic fixtures defined
- [ ] Deterministic seeding (tests)
- [ ] Relationship building logic
- [ ] Environment-specific seeds
- [ ] Database reset script
- [ ] E2E test fixtures

© patricio0312rev · MIT · patricio0312rev/skills

Similar skills

All skills for Data and databases →

From the same set148

The whole set →
contract-testing-builder contract-testing-builder implements API contract testing with Pact, OpenAPI, and JSON Schema to catch breaking changes before deploying services. CX Codex +1 266installs rollback-workflow-builder rollback-workflow-builder builds deployment rollback workflows, runbooks, and recovery checks. Use it for production incidents or automatic recovery after a failed release. CX Codex +1 266installs vector-db-setup vector-db-setup sets up vector databases like Pinecone and Chroma with OpenAI embedding pipelines and similarity search queries for AI apps. CX Codex +1 266installs capacity-planning-helper capacity-planning-helper is a Claude Code skill that turns a traffic forecast into instance counts, database and cache sizing, and a monthly AWS cost estimate. CX Codex +1 265installs docs-starter-kit docs-starter-kit generates documentation templates for open-source and internal codebases, including README, CONTRIBUTING, and security policies. CX Codex +1 265installs prompt-regression-tester prompt-regression-tester compares prompt revisions across structured test suites, detects regressions, and drafts targeted fixes. CX Codex +1 265installs release-automation-builder release-automation-builder is a Claude Code skill for automating releases and package publishing. It responds to requests about versioning, changelogs, or release workflows. CX Codex +1 265installs postmortem-writer postmortem-writer turns an incident into a written postmortem: timeline, root cause, contributing factors, action items with owners. Runs as a skill inside your coding agent. CX Codex +1 265installs

Project sponsors

Companies that keep this analytics open