© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•10mo ago•
1 reply
codevogel

Drizzle-seed and sequential dates

Say I have a schema with two
DateTime
DateTime
fields,
started_at
started_at
and
ended_at
ended_at


How would I use drizzle-seed and its
refine
refine
function to seed my database with these values differening not more than say, 5 days?

Aka if started_at seeds on
01-05-2025
01-05-2025
then the minimum should be the same and the maximum for ended_at should be
05-05-2025
05-05-2025


If not possible with the
refine
refine
function, what would be best practice for this?

Here's an example seed script I was working on when I ran into this problem:

import { reset, seed } from "drizzle-seed";
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";
import *  as schema from "../src/lib/server/db/schema";
import "dotenv/config";

async function reseed_db() {
    if (!process.env.DATABASE_URL) throw new Error('DATABASE_URL is not set');

    const client = mysql.createPool(process.env.DATABASE_URL);
    const db = drizzle(client, { schema, mode: 'default' });
    console.log("Resetting database...");
    await reset(db, schema);
    console.log("Reseeding database...");
    await seed(db, schema).refine((f) => ({
        user: {
            count: 20,
            columns: {
                name: f.firstName(),
                createdAt: f.date({ minDate: "2025-01-01", maxDate: "2025-04-01" }),
                dateOfBirth: f.date({ minDate: "1990-01-01", maxDate: "2000-01-01" }),
            },
        },
        session: {
            count: 100,
            columns: {
                score: f.int({ minValue: 0, maxValue: 1500 }),
                accuracy: f.number({ minValue: 0, maxValue: 1, precision: 100 }),
         // How would I add sequential created_at and ended_at datetimes here?
            },

        },
    }));
    console.log("Database reseeded successfully");
    client.end();
}

async function main() {
    await reseed_db();
}

main()
import { reset, seed } from "drizzle-seed";
import { drizzle } from "drizzle-orm/mysql2";
import mysql from "mysql2/promise";
import *  as schema from "../src/lib/server/db/schema";
import "dotenv/config";

async function reseed_db() {
    if (!process.env.DATABASE_URL) throw new Error('DATABASE_URL is not set');

    const client = mysql.createPool(process.env.DATABASE_URL);
    const db = drizzle(client, { schema, mode: 'default' });
    console.log("Resetting database...");
    await reset(db, schema);
    console.log("Reseeding database...");
    await seed(db, schema).refine((f) => ({
        user: {
            count: 20,
            columns: {
                name: f.firstName(),
                createdAt: f.date({ minDate: "2025-01-01", maxDate: "2025-04-01" }),
                dateOfBirth: f.date({ minDate: "1990-01-01", maxDate: "2000-01-01" }),
            },
        },
        session: {
            count: 100,
            columns: {
                score: f.int({ minValue: 0, maxValue: 1500 }),
                accuracy: f.number({ minValue: 0, maxValue: 1, precision: 100 }),
         // How would I add sequential created_at and ended_at datetimes here?
            },

        },
    }));
    console.log("Database reseeded successfully");
    client.end();
}

async function main() {
    await reseed_db();
}

main()
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

drizzle-seed
Drizzle TeamDTDrizzle Team / help
13mo ago
Drizzle-Seed null values
Drizzle TeamDTDrizzle Team / help
12mo ago
drizzle-seed and many-to-many relationship
Drizzle TeamDTDrizzle Team / help
8mo ago
Drizzle seed stuck and no info displayed
Drizzle TeamDTDrizzle Team / help
14mo ago