Skip to main content
doc0blade47/drizzle-ormdocumentation home
Sign in

Seeding Test Data

Last updated Oct 12, 2026100% grounded

Overview

Database Seeding Essentials

Populating your database with realistic dummy data for testing and development is easy using the built-in seeding tools. Instead of writing manual insert scripts, you can automatically generate rows of realistic names, emails, addresses, numbers, and more that respect your table structures and relationships.

To quickly populate your database with default dummy data, pass your database connection and schema object to the seeding function.

import { seed } from 'drizzle-seed';
 
// Basic seeding with default row counts
await seed(db, schema);

Note

The database seeding features currently support PostgreSQL, MySQL, and SQLite databases.

Controlling Row Counts and Reproducibility

You can customize how many rows are generated and ensure your test data is reproducible by providing an options object.

// Generate 100,000 rows per table
await seed(db, schema, { count: 100000 });
 
// Generate data with a fixed seed so it is identical every time you run it
await seed(db, schema, { count: 100000, seed: 1 });
OptionDescription
countThe number of rows you want to generate per table.
seedA number controlling the pseudo-random state. Using the same seed number produces the exact same generated data on every run.
versionSelects the generator version (1 or 2).

Customizing Data with Refinements

You can tailor the generated data for specific tables and columns by chaining a refinement function onto your seed call. This lets you apply specific generators, set unique constraints, or use custom value lists.

await seed(db, schema, { count: 1000 }).refine((funcs) => ({
  users: {
    columns: {
      name: funcs.firstName({ isUnique: true }),
      email: funcs.email(),
      phone: funcs.phoneNumber({ template: "+380 99 ###-##-##" }),
      password: funcs.string({ isUnique: true }),
    },
    count: 10000,
  },
  posts: {
    columns: {
      title: funcs.valuesFromArray({
        values: ["Title1", "Title2", "Title3", "Title4", "Title5"],
      }),
      content: funcs.loremIpsum({ sentencesCount: 3 }),
    },
  },
}));

Available Data Generators

You can use various generator functions inside your refinement callbacks to populate columns with specific types of realistic data.

Generator FunctionDescription
funcs.city()Generates realistic city names.
funcs.streetAddress()Generates realistic street addresses.
funcs.jobTitle()Generates realistic job titles.
funcs.postcode()Generates postal codes.
funcs.state()Generates US state names.
funcs.companyName()Generates company names.
funcs.loremIpsum()Generates placeholder text sentences.
funcs.point()Generates 2D coordinate points.
funcs.line()Generates 2D line parameters.
funcs.weightedRandom()Calls different generators based on assigned probability weights.

Tip

Many generators accept options like isUnique: true to ensure all generated values in that column are unique, or arraySize to generate lists of values.


Clearing Existing Data

If you need to clear out existing data before running your seeds, you can use the reset utility. This safely clears all data from the specified tables while handling foreign key constraints automatically.

import { reset } from 'drizzle-seed';
 
// Remove all data from the specified tables
await reset(db, { users, posts });
Was this page helpful?