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.
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
The primary function for initiating the seeding process. Always a named import.
import { seed } from 'drizzle-seed';
Used to clear tables before seeding, typically imported alongside `seed`.
import { reset } from 'drizzle-seed';
Though not exported directly as `Fake`, the `refine` callback receives a 'faker' object, often conceptually referred to as the 'Fake' data generator. For direct column value generation, the `refine` function provides helper methods rather than a top-level `Fake` export. The `f` argument in `refine((f) => ...)` is an instance of the internal faker.
import { seed, Fake } from 'drizzle-seed';
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.
import 'dotenv/config';
import { pgTable, serial, text, timestamp, integer } from 'drizzle-orm/pg-core';
import { drizzle } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';
import { seed, reset } from 'drizzle-seed';
export const users = pgTable('users', {
id: serial('id').primaryKey(),
name: text('name').notNull(),
email: text('email').notNull().unique(),
age: integer('age').notNull(),
createdAt: timestamp('created_at').notNull().defaultNow(),
});
export const posts = pgTable('posts', {
id: serial('id').primaryKey(),
title: text('title').notNull(),
content: text('content'),
userId: integer('user_id').references(() => users.id, { onDelete: 'cascade' }).notNull(),
createdAt: timestamp('created_at').notNull().defaultNow(),
});
const pool = new Pool({
connectionString: process.env.DATABASE_URL ?? 'postgresql://user:password@localhost:5432/drizzle_test_db',
});
const db = drizzle(pool, { schema: { users, posts } });
async function runSeed() {
try {
console.log('Starting database reset...');
// Clears all specified tables, respecting foreign key constraints.
await reset(db, { users, posts });
console.log('Database reset complete.');
console.log('Starting database seeding...');
await seed(db, { users, posts }).refine((f) => ({
users: {
count: 5, // Create 5 users
columns: {
name: () => f.fullName(),
email: () => f.email(),
age: () => f.number.int({ min: 18, max: 80 }),
},
with: {
posts: 3, // Each user gets 3 posts
},
},
posts: {
columns: {
title: () => f.lorem.sentence(),
content: () => f.lorem.paragraph(),
},
},
}));
console.log('Database seeding complete.');
} catch (error) {
console.error('Seeding failed:', error);
process.exit(1);
} finally {
await pool.end();
process.exit(0);
}
}
runSeed();
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.