drizzle-team / drizzle-team/drizzle-orm

[BUG]: drizzle-seed not respecting the count value for all tables

Open
#4,050 2 comments 2 reactions 0 assignees View on GitHub
bug drizzle/seed priority
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

drizzle-orm: ^0.38.4

### What version of `drizzle-kit` are you using?

drizzle-kit: ^0.30.2

### Other packages

drizzle-seed: ^0.3.1

### Describe the Bug

## Bug: Count values not respected in drizzle-seed

### Description
When using `drizzle-seed`, the `count` parameter is being ignored for most tables, defaulting to 10 records regardless of specified count. Only the `waitlist` table respects the count parameter.

### Reproduction
```ts
// seed.ts
import "dotenv/config";
import { seed, reset } from "drizzle-seed";
import { db } from "..";
import * as schema from "./schema";

async function main() {
await reset(db, schema);

await seed(db, schema).refine((f) => ({
organizations: {
count: 5,
columns: {
name: f.companyName(),
slug: f.default({
defaultValue: (values: any) =>
values.name.toLowerCase().replace(/[^a-z0-9]+/g, "-"),
}),
sport: f.default({ defaultValue: "BASKETBALL" }),
type: f.valuesFromArray({
values: [
{ weight: 0.5, values: ["ASSOCIATION"] },
{ weight: 0.3, values: ["CONFERENCE"] },
{ weight: 0.2, values: ["LEAGUE"] },
],
}),
status: f.valuesFromArray({
values: [
{ weight: 0.9, values: ["ACTIVE"] },
{ weight: 0.1, values: ["INACTIVE"] },
],
}),
},
with: {
organizationOfficials: [
{ weight: 0.2, count: [50, 75] },
{ weight: 0.5, count: [76, 150] },
{ weight: 0.3, count: [151, 300] },
],
},
},

officials: {
count: 500,
columns: {
certificationLevel: f.valuesFromArray({
values: [
{ weight: 0.4, values: ["1"] },
{ weight: 0.3, values: ["2"] },
{ weight: 0.15, values: ["3"] },
{ weight: 0.1, values: ["4"] },
{ weight: 0.05, values: ["5"] },
],
}),
yearsOfExperience: f.int({ minValue: 0, maxValue: 30 }),
status: f.valuesFromArray({
values: [
{ weight: 0.9, values: ["ACTIVE"] },
{ weight: 0.1, values: ["INACTIVE"] },
],
}),
},
},

games: {
count: 1000,
columns: {
date: f.date({ minDate: "2024-01-01", maxDate: "2024-12-31" }),
location: f.valuesFromArray({
values: [
"Main Gymnasium",
"Auxiliary Gymnasium",
"Recreation Center",
"Field House",
"Arena",
"Community Center",
"Sports Complex",
"High School Gym",
"University Arena",
"Civic Center",
"Athletic Complex",
"Memorial Stadium",
"Youth Center",
"Regional Sports Facility",
],
}),
status: f.valuesFromArray({
values: [
{ weight: 0.5, values: ["SCHEDULED"] },
{ weight: 0.1, values: ["IN_PROGRESS"] },
{ weight: 0.4, values: ["COMPLETED"] },
],
}),
},
with: {
gameOfficials: [2, 3],
evaluations: [
{ weight: 0.5, count: [0] },
{ weight: 0.3, count: [1] },
{ weight: 0.15, count: [2] },
{ weight: 0.05, count: [3, 4] },
],
},
},

gameOfficials: {
columns: {
role: f.valuesFromArray({
values: [
{ weight: 0.34, values: ["CREW_CHIEF"] },
{ weight: 0.33, values: ["REFEREE"] },
{ weight: 0.33, values: ["UMPIRE"] },
],
}),
},
},

organizationOfficials: {
columns: {
role: f.valuesFromArray({
values: [
{ weight: 0.8, values: ["MEMBER"] },
{ weight: 0.15, values: ["ADMIN"] },
{ weight: 0.05, values: ["ASSIGNOR"] },
],
}),
},
},

evaluations: {
columns: {
rating: f.valuesFromArray({
values: [
{ weight: 0.1, values: [5] },
{ weight: 0.3, values: [4] },
{ weight: 0.4, values: [3] },
{ weight: 0.15, values: [2] },
{ weight: 0.05, values: [1] },
],
}),
notes: f.default({
defaultValue: () => {
const templates = [
"Game management was {quality}. {specific} Mechanics were {mechanic_quality}.",
"Showed {quality} court presence. {specific} Communication with partners was {communication}.",
"Foul judgment was {quality}. {specific} Game flow management was {flow}.",
"Position adjustments were {quality}. {specific} Rules knowledge demonstrated was {rules}.",
"Game control was {quality}. {specific} Partner collaboration was {collaboration}.",
];

const qualities = [
"excellent",
"very good",
"good",
"adequate",
"inconsistent",
"poor",
];
const specifics = [
"Made strong calls in crucial moments.",
"Maintained good positioning throughout.",
"Could improve consistency on block/charge calls.",
"Handled coach interactions professionally.",
"Needs work on rotation mechanics.",
"Demonstrated excellent rules knowledge.",
"Showed good judgment on tough plays.",
"Communication with partners needs improvement.",
"Managed bench areas effectively.",
"Game flow control was notable.",
];
const mechanics = [
"precise",
"very good",
"mostly accurate",
"inconsistent",
"needs improvement",
];
const communications = [
"excellent",
"effective",
"adequate",
"inconsistent",
"needs improvement",
];
const flows = [
"excellent",
"smooth",
"generally good",
"choppy",
"needs work",
];
const rules = [
"excellent",
"solid",
"adequate",
"inconsistent",
"needs review",
];
const collaboration = [
"excellent",
"effective",
"adequate",
"needs improvement",
"poor",
];

const template =
templates[Math.floor(Math.random() * templates.length)];
const randomFrom = (arr: string[]): string =>
arr[Math.floor(Math.random() * arr.length)] ?? "fail";

return template
?.replace("{quality}", randomFrom(qualities))
?.replace("{specific}", randomFrom(specifics))
?.replace("{mechanic_quality}", randomFrom(mechanics))
?.replace("{communication}", randomFrom(communications))
?.replace("{flow}", randomFrom(flows))
?.replace("{rules}", randomFrom(rules))
?.replace("{collaboration}", randomFrom(collaboration));
},
}),
status: f.valuesFromArray({
values: [
{ weight: 0.15, values: ["DRAFT"] },
{ weight: 0.7, values: ["SUBMITTED"] },
{ weight: 0.15, values: ["APPROVED"] },
],
}),
},
},

users: {
count: 200,
columns: {
email: f.email(),
name: f.fullName(),
onboardingComplete: f.valuesFromArray({
values: [
{ weight: 0.9, values: [true] },
{ weight: 0.1, values: [false] },
],
}),
},
},

waitlist: {
count: 300,
columns: {
email: f.email(),
status: f.valuesFromArray({
values: [
{ weight: 0.7, values: ["PENDING"] },
{ weight: 0.2, values: ["APPROVED"] },
{ weight: 0.1, values: ["REJECTED"] },
],
}),
},
},
}));
}

main().catch((e) => {
console.error(e);
process.exit(1);
});

```
### Expected Behavior
- Each table should generate the number of records specified in its `count` parameter

### Actual Behavior
- All tables except `waitlist` default to 10 records regardless of count value
- `waitlist` table correctly generates specified number of records

![Image](https://github.com/user-attachments/assets/bf4d0f05-9993-4d96-81b9-e1e9dbf528cb)

### Environment
- Package: drizzle-seed
- Database: PostgreSQL (neon)
- Node version: 22.8

### Impact
This severely limits the ability to generate realistic test data sets, especially for testing pagination, performance, and data relationships at scale.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.