drizzle-team / drizzle-team/drizzle-orm
[BUG]: drizzle-seed throws on tables with two composite unique constraints sharing a column
- 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?
1.0.0-beta.22
### What version of `drizzle-kit` are you using?
1.0.0-beta.22
### Other packages
drizzle-seed@1.0.0-beta.22
### Describe the Bug
`seed()` throws when a table declares **two composite unique constraints that share a column**. This is a common multi-tenant pattern: a `(tenant_id, id)` composite unique to serve as a composite-FK target, plus a `(tenant_id, business_key)` unique for the per-tenant business rule. `PostgreSQL` supports this without issue, but `drizzle-seed` rejects it.
**Error**
```
Error: Currently, multiple composite unique keys that share the same column are not supported.
at SeedService.generatePossibleGenerators (drizzle-seed/src/SeedService.ts:359)
at seedPostgres (drizzle-seed/src/pg-core/index.ts:63)
at seedFunc (drizzle-seed/src/index.ts:347)
...
```
**Minimal reproduction**
```ts
import { pgTable, uuid, text, unique } from "drizzle-orm/pg-core";
import { drizzle } from "drizzle-orm/postgres-js";
import { seed } from "drizzle-seed";
import postgres from "postgres";
const products = pgTable(
"products",
{
id: uuid("id").primaryKey().defaultRandom(),
orgId: uuid("org_id").notNull(),
name: text("name").notNull(),
},
(t) => [
// composite-FK target so children can enforce same-tenant references
unique("products_org_id_unique").on(t.orgId, t.id),
// per-tenant business uniqueness
unique("products_org_name_unique").on(t.orgId, t.name),
],
);
const db = drizzle(postgres(process.env.DATABASE_URL!));
await seed(db, { products }); // throws
```
**Expected behavior**
`drizzle-seed` should generate rows that satisfy both composite unique constraints (both constraints are independently valid in PostgreSQL), rather than throwing.
**Actual behavior**
`generatePossibleGenerators` throws unconditionally as soon as two composite unique constraints share a column. Providing explicit generators via `.refine()` for the columns involved does not help — the check is structural and runs before generators are applied.
Contributor guide
Research direction
Start in drizzle-seed/src/SeedService.ts at generatePossibleGenerators, then trace the calls through drizzle-seed/src/pg-core/index.ts and drizzle-seed/src/index.ts. Reproduce the schema from the issue and determine how generation handles two composite unique constraints sharing a column; done means seed() completes and generated rows satisfy both constraints without the structural rejection.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, typescript
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100