drizzle-team / drizzle-team/drizzle-orm
[FEATURE]: drizzle-seed: Grouped column values with different generator configs
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Feature hasn't been suggested before.
- [x] I have verified this feature I'm about to request hasn't been suggested before.
### Describe the enhancement you want to request
It would be nice if it were possible to group certain columns and their generators, e.g. by doing a weightedRandom call. We have many cases of cross column constraints in our database. For example: If `branch = "branch_a"`, the JSON in column `fields` needs to adhere to a specific format. Or: if `state = "PAUSED"`, the extra columns `paused_during` and `paused_reason` are set.
I have an example of how this might work from a refine call in drizzle-seed
```tsx
tableA: {
columns: {
id: f.string(),
// ...
...f.weightedRandom([
{
weight: 0.4,
value: {
branch: f.default({ defaultValue: "branch_a" }),
fields: f.valuesFromArray({
values: Array.from({ length: 20 }, () => generateAlphaFields()),
}),
},
},
{
weight: 0.4,
value: {
branch: f.default({ defaultValue: "branch_b" }),
fields: f.valuesFromArray({
values: Array.from({ length: 20 }, () => generateBetaFields()),
}),
},
},
{
weight: 0.2,
value: {
branch: f.default({ defaultValue: "branch_c" }),
fields: f.valuesFromArray({
values: Array.from({ length: 20 }, () => generateGammaFields()),
}),
},
},
]),
},
count: 60,
}
```
This is basically how it worked in snaplet/seed which we have used before. Though I think snaplet seed also used a different strategy for generating data, generating the entire data object in the seed config instead of defining a generator for each column, so I'm not sure if you can do a similar thing in drizzle-seed.
Thank you for your consideration!
Contributor guide
Assessment
This issue has not been assessed yet.