Skip to content
Skills Library
Programming · Building & coding

data-seeding

/data-seeding

Create or update database seed scripts for development and testing environments. Use when setting up test data, initializing development databases, creating demo environments, resetting to known state, or generating realistic sample data.

Licence
MIT
Last repository change
28.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 28.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Create or update database seed scripts for development and testing environments. Use when setting up test data, initializing development databases, creating demo environments, resetting to known state, or generating realistic sample data.

Original author description

Create or update database seed scripts for development and testing environments. Use when setting up test data, initializing development databases, creating demo environments, resetting to known state, or generating realistic sample data.

How it works

  1. Running Seeds
  2. Basic Seed Pattern
  3. Main Seed Runner
  4. Seed with Faker.js
  5. Environment-Specific Seeds
  6. Idempotent Seeds (Upsert)
  7. Check Before Insert
  8. Transactions
  9. CLI for Selective Seeding
  10. Best Practices
Original SKILL.md headings · 163 lines, 470 words
SKILL.md preview
---
name: data-seeding
description: Create or update database seed scripts for development and testing environments. Use when setting up test data, initializing development databases, creating demo environments, resetting to known state, or generating realistic sample data.
allowed-tools: Read, Edit, Write, Bash
---

# Data Seeding Skill

Seed scripts live in `packages/database/src/seed/`.

## Running Seeds

```bash
pnpm -F @sgcarstrends/database db:seed           # Run all seeds
pnpm -F @sgcarstrends/database db:seed:cars      # Seed specific table
```

## Basic Seed Pattern

```typescript
// packages/database/src/seed/cars.ts
import { db } from "../index";
import { cars } from "../db/schema";
import { nanoid } from "nanoid";

export async function seedCars() {
  console.log("Seeding cars...");

  const carData = [
    { id: nanoid(), make: "Toyota", model: "Camry", vehicleClass: "Sedan", fuelType: "Petrol", month: "2024-01", number: 150 },
    { id: nanoid(), make: "Honda", model: "Civic", vehicleClass: "Sedan", fuelType: "Petrol", month: "2024-01", number: 120 },
  ];

  await db.insert(cars).values(carData);
  console.log(`Seeded ${carData.length} cars`);
}
```

## Main Seed Runner

```typescript
// packages/database/src/seed/index.ts
export async function seed() {
  console.log("Starting database seed...");

  await clearDatabase();  // Optional: clear existing data
  await seedCars();
  await seedCOE();
  await seedPosts();

  console.log("Database seeded successfully!");
}

async function clearDatabase() {
  // Delete in reverse order of dependencies
  await db.delete(posts);
  await db.delete(coe);
  await db.delete(cars);
}
```

## Seed with Faker.js

```bash
pnpm -F @sgcarstrends/database add -D @faker-js/faker
```

```typescript
import { faker } from "@faker-js/faker";

export async function seedRealisticCars(count = 100) {
  const makes = ["Toyota", "Honda", "BMW", "Mercedes"];
  const carData = Array.from({ length: count }, () => ({
    id: nanoid(),
    make: faker.helpers.arrayElement(makes),
    model: faker.vehicle.model(),
    month: faker.date.between({ from: "2020-01-01", to: "2024-12-31" }).toISOString().slice(0, 7),
    number: faker.number.int({ min: 10, max: 500 }),
  }));

  // Batch insert for performance
  const batchSize = 50;
  for (let i = 0; i < carData.length; i += batchSize) {
    await db.insert(cars).values(carData.slice(i, i + batchSize));
  }
}
```

## Environment-Specific Seeds

```typescript
export async function seed() {
  const env = process.env.NODE_ENV || "development";

  switch (env) {
    case "development":
      await seedDevelopment();  // Small, predictable dataset
      break;
    case "test":
      await seedTesting();  // Minimal, deterministic data
      break;
    case "staging":
      await seedStaging();  // Larger, production-like dataset
      break;
  }
}
```

## Idempotent Seeds (Upsert)

```typescript
await db.insert(cars).values(carData).onConflictDoUpdate({
  target: cars.id,
  set: { make: carData[0].make, number: carData[0].number, updatedAt: new Date() },
});
```

## Check Before Insert

```typescript
export async function seedIfEmpty() {
  const existing = await db.select().from(cars).limit(1);
  if (existing.length > 0) {
    console.log("Database has data, skipping seed");
    return;
  }
  await seedCars();
}
```

## Transactions

```typescript
await db.transaction(async (tx) => {
  await tx.insert(cars).values([...carData]);
  await tx.insert(coe).values([...coeData]);
});
```

## CLI for Selective Seeding

```typescript
// packages/database/scripts/seed-cli.ts
const seeders = { cars: seedCars, coe: seedCOE, posts: seedPosts, all: seedAll };
const target = process.argv[2] as keyof typeof seeders;

if (!target || !seeders[target]) {
  console.error("Usage: pnpm db:seed [cars|coe|posts|all]");
  process.exit(1);
}

seeders[target]().then(() => process.exit(0)).catch(() => process.exit(1));
```

## Best Practices

1. **Idempotent**: Safe to run multiple times (use upserts or check-before-insert)
2. **Environment-Specific**: Different data for dev/test/staging
3. **Batch Inserts**: Use batching for large datasets
4. **Relationships**: Seed parent tables first
5. **Transactions**: Use for atomic seeding
6. **Logging**: Provide clear progress feedback

## References

- `packages/database/AGENTS.md` for schema details
- See `schema-design` skill for migrations

Versions

RepositoryScoreLicence
This page · motormetrics/motormetrics100MIT
motormetrics/motormetrics100MIT

Database snapshot: 13.11.2026 · package version e1a533aa5687 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 1 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100database-seeding
    Populate databases with realistic, reproducible test data for development, testing, and staging environments. Use when the user requests database seeding or provides relevant inputs for this workflow.
  • 100generating-database-seed-data
    Process this skill enables AI assistant to generate realistic test data and database seed scripts for development and testing environments. it uses faker libraries to create realistic data, maintains relational integrity, and allows configurable data volumes. u... Use when…
  • 100generating-database-seed-data
    Process this skill enables AI assistant to generate realistic test data and database seed scripts for development and testing environments. it uses faker libraries to create realistic data, maintains relational integrity, and allows configurable data volumes. u... Use when…
  • 100seed-data
    Generates comprehensive, realistic seed data for all environments (dev, test, demo, stress). This skill should be used when the user asks to "generate seed data", "create test data", "populate the database", "create demo data", "generate edge case data", or "set up seed scripts"…
  • 100generate-sample-data
    Generate mock/sample data from Zod schemas for testing, development, and mocks. Use when creating sample data generators, setting up test fixtures, populating mock APIs, or generating realistic fake data for development.
  • 100seedmint
    Generate realistic sample/seed/mock data from a schema (TypeScript, Zod, Prisma, Drizzle, SQL, JSON) in a chosen locale and format, so prototypes and UI reviews are not empty. Use when the user asks for fake data, seed data, mock data, fixtures or demo data.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.