Skip to content

Instantly share code, notes, and snippets.

View lwensveen's full-sized avatar

Lodewijk Wensveen lwensveen

View GitHub Profile
@lwensveen
lwensveen / README.md
Created April 8, 2025 15:34
Drizzle-Seed Junction Table Workaround: Avoiding Duplicate Key Violations

Temporary Drizzle-Seed Junction Table Workaround

This is a temporary solution for seeding databases with Drizzle ORM (drizzle-seed) when junction tables cause duplicate key violations. It seeds main tables first using seed, then manually seeds junction tables with fetched IDs to ensure uniqueness.

Usage

  1. Replace schema and db imports with your own schema and database connection.
  2. Update mainTables with your main entity tables (e.g., users, products).
  3. Add your junction tables in the seeding section (e.g., userProducts).
  4. Run with your preferred runtime (e.g., bun run seed.ts).