Drizzle Seed is a TypeScript library designed for generating deterministic, yet realistic, fake data to populate databases in conjunction with Drizzle ORM. It leverages a seedable pseudorandom number generator (pRNG) to ensure that generated data is consistent and reproducible across different runs, which is crucial for reliable testing, development, and debugging workflows. The library currently stands at version 0.3.1 (within the Drizzle ecosystem's 0.x series for utilities), with ongoing active development that typically follows the release cadence and advancements of Drizzle ORM. Key differentiators include its tight integration with Drizzle ORM's type safety, its focus on reproducible data sets via pRNG, and a flexible API for refining data generation at column and table levels, including handling complex relationships. It enables developers to easily reset and re-seed their databases with predictable data.
npm install drizzle-seedVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a Drizzle schema, connect to a PostgreSQL database, then use `reset` to clear tables and `seed` to populate them with deterministic fake data, including related entities. It shows column-level data generation and `with` for relations.
Upgrade to `drizzle-seed@0.3.0` or higher. If upgrading is not immediately possible, a manual workaround is to run `SELECT setval('your_table_id_seq', (SELECT MAX(id) FROM your_table));` after seeding to update the sequence.Ensure that your Drizzle schema column definitions match the actual casing in your database when using `drizzle-seed`, or manually specify column names in `refine` to align with the database's expected casing. This issue can be subtle as `drizzle-orm` itself handles casing, but `drizzle-seed` has had reports of not respecting it.
Execute your seed script directly using `node your-seed-script.js`, `ts-node your-seed-script.ts`, or similar runtime commands. For example: `bun run ./src/db/seed.ts`.
Ensure `drizzle-orm` is updated to version `0.36.4` or higher in your project dependencies.
Always include all related tables in the schema argument of the `seed` function. Ensure `not-null` foreign key columns are either populated by `with` for related entities or have an explicit generator defined in `refine`. For complex or circular relations, manually provide `references` definitions in your Drizzle schema.
Verify your `drizzle.config.ts` casing settings and ensure your Drizzle schema column names precisely match the database, or explicitly define column names in the `refine` callback of `drizzle-seed` to override.
Upgrade `drizzle-seed` to version 0.3.0 or newer. As a temporary workaround for older versions, manually reset the sequence after seeding: `await db.execute(sql`SELECT setval('users_id_seq', (SELECT MAX(id) FROM users));`);`.Run your TypeScript seed file directly using a runtime like `ts-node`, `bun`, or `node` (after transpilation). Example: `ts-node src/seed.ts`.
Ensure all tables involved in a `with` relationship are included in the schema argument of the `seed` function, and that explicit foreign key `references` are correctly defined in your Drizzle schema (e.g., `userId: integer('user_id').references(() => users.id)`).