new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Drizzle ORM · all subjects

drizzle-orm/seeding

102 notes in this subject, read out of this brain and free to use. This is page 2 of 2.

drizzle-seed version 2 breaking changes

Version 2 changed two generators: string() (both unique and non-unique) and interval({ isUnique: true }). The interval generator was changed because the old version could produce intervals like '1 minute 60 seconds' and '2 minutes 0 seconds' as distinct values, but SingleStore normalizes them to the same value, causing unique constraint violations. The string generator was updated to generate unique strings based on the text column length parameter (e.g., varchar(20)).

drizzle-seed version 4 breaking changes

Version 4 changed the uuid generator. UUID values generated by the old uuid generator fail Zod's v4 UUID validation. The new generator produces UUIDs that pass Zod v4 validation.

drizzle-seed version 3 breaking changes

Version 3 changed the hash generating function to produce consistent hashes regardless of Node.js or Bun version. The previous hash function generated different hashes depending on whether Bun or Node.js was used and varied across Node.js versions. All generators output different values in version 3 compared to the previous version, even with the same seed number.

drizzle-seed version 2 string generator affected use case

You are affected by the version 2 string generator changes if your table includes columns of text-like types (char, varchar, binary, varbinary, text) with a maximum length parameter or if you use unique columns of these types and apply the string generator with f.string({ isUnique: true }).

drizzle-seed versioning overview

drizzle-seed uses versioning to manage outputs for static and dynamic data generation. Versioning ensures determinism—values remain unchanged when using the same seed number. If changes are made to static data sources or dynamic data generation logic, the version updates, allowing you to choose between the previous version or the latest. You can upgrade to the latest drizzle-seed version for new features like additional generators while maintaining deterministic outputs with a previous version if needed.

drizzle-seed version history and API changes

drizzle-seed version history: v1 (npm 0.1.1, no generators changed), v2 (npm 0.2.1, changed string() and interval({ isUnique: true })), v3 (npm 0.4.0, changed hash generating function), v4 LTS (npm 1.0.0-beta.8, changed uuid generator).

int generator parameters

The int generator creates integers within a range. Parameters: isUnique (boolean, default: database column uniqueness) - controls uniqueness; maxValue (number | bigint, default: 1000 if not unique, count * 10 if unique) - upper bound; minValue (number | bigint, default: -maxValue) - lower bound; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

boolean generator parameters

The boolean generator creates true or false values. Parameters: arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

date generator parameters

The date generator creates dates within a range. Parameters: minDate (string | Date, default: '2024-05-08' - 4 years if maxDate not set, or maxDate - 8 years if maxDate is set) - lower bound; maxDate (string | Date, default: '2024-05-08' + 4 years if minDate not set, or minDate + 8 years if minDate is set) - upper bound; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified. If only one parameter is provided, the unspecified parameter is calculated by adding or subtracting 8 years to/from the specified one.

time generator parameters

The time generator creates times in 24-hour format. Parameters: min (string | Date, default: '00:00:00.000Z') - lower bound; max (string | Date, default: '23:59:59.999Z') - upper bound; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

timestamp generator parameters

The timestamp generator creates timestamps. Parameters: min (string | Date, default: '2024-05-08' - 2 years if max not set, or max - 4 years if max is set) - lower bound; max (string | Date, default: '2024-05-08' + 2 years if min not set, or min + 4 years if min is set) - upper bound; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

datetime generator parameters

The datetime generator creates datetime objects. Parameters: min (string | Date, default: '2024-05-08' - 2 years if max not set, or max - 4 years if max is set) - lower bound; max (string | Date, default: '2024-05-08' + 2 years if min not set, or min + 4 years if min is set) - upper bound; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

year generator parameters

The year generator creates years in YYYY format. Parameters: arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

json generator parameters

The json generator creates JSON objects with a fixed structure. It randomly picks one of two possible structures: {email, name, isGraduated, hasJob, salary, startedWorking, visitedCountries} or {email, name, isGraduated, hasJob, visitedCountries}. Parameters: arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

interval generator parameters

The interval generator creates time intervals (example generated value: '1 year 12 days 5 minutes'). Parameters: isUnique (boolean, default: database column uniqueness) - controls uniqueness; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

string generator parameters

The string generator creates random strings. Parameters: isUnique (boolean, default: database column uniqueness) - controls uniqueness; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

uuid generator parameters

The uuid generator creates v4 UUID strings. Parameters: arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

firstName generator parameters

The firstName generator creates person first names. Parameters: isUnique (boolean, default: database column uniqueness) - controls uniqueness; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

lastName generator parameters

The lastName generator creates person last names. Parameters: isUnique (boolean, default: database column uniqueness) - controls uniqueness; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

fullName generator parameters

The fullName generator creates person full names. Parameters: isUnique (boolean, default: database column uniqueness) - controls uniqueness; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

email generator parameters

The email generator creates unique email addresses. Parameters: arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

phoneNumber generator parameters

The phoneNumber generator creates unique phone numbers with three usage patterns. First pattern uses template property (string, required) where '#' symbols are replaced with generated digits. Second pattern uses prefixes (string[], not compatible with template) and generatedDigitsNumbers (number | number[], default: 7 if prefixes defined) to append digits to prefixes. Third pattern allows different digit counts per prefix by passing generatedDigitsNumbers as an array matching the length of prefixes. All patterns support arraySize (number, optional) parameter for creating one-dimensional arrays.

country generator parameters

The country generator creates country names. Parameters: isUnique (boolean, default: database column uniqueness) - controls uniqueness; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

city generator parameters

The city generator creates city names. Parameters: isUnique (boolean, default: database column uniqueness) - controls uniqueness; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

streetAddress generator parameters

The streetAddress generator creates street addresses. Parameters: isUnique (boolean, default: database column uniqueness) - controls uniqueness; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

jobTitle generator parameters

The jobTitle generator creates job titles. Parameters: arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

postcode generator parameters

The postcode generator creates postal codes. Parameters: isUnique (boolean, default: database column uniqueness) - controls uniqueness; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

state generator parameters

The state generator creates US state names. Parameters: arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

companyName generator parameters

The companyName generator creates company names. Parameters: isUnique (boolean, default: database column uniqueness) - controls uniqueness; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

loremIpsum generator parameters

The loremIpsum generator creates lorem ipsum text sentences. Parameters: sentencesCount (number, default: 1) - number of sentences to generate as one string value; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

point generator parameters

The point generator creates 2D points within specified ranges for x and y coordinates. Parameters: isUnique (boolean, default: database column uniqueness) - controls uniqueness; maxXValue (number, default: 10 * 1000 if not unique, 10 * count if unique) - x upper bound; minXValue (number, default: -maxXValue) - x lower bound; maxYValue (number, default: 10 * 1000 if not unique, 10 * count if unique) - y upper bound; minYValue (number, default: -maxYValue) - y lower bound; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

bitString generator parameters

The bitString generator creates bit strings based on specified parameters. Parameters: isUnique (boolean, default: database column uniqueness) - controls uniqueness; dimensions (number, default: database column bit-length) - desired length of each bit string (e.g., dimensions = 3 produces values like '010'); arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

line generator parameters

The line generator creates 2D lines using the equation a*x + b*y + c = 0. Parameters: isUnique (boolean, default: database column uniqueness) - controls uniqueness; maxAValue (number, default: 10 * 1000 if not unique, 10 * count if unique) - a upper bound; minAValue (number, default: -maxAValue) - a lower bound; maxBValue (number, default: 10 * 1000 if not unique, 10 * count if unique) - b upper bound; minBValue (number, default: -maxBValue) - b lower bound; maxCValue (number, default: 10 * 1000 if not unique, 10 * count if unique) - c upper bound; minCValue (number, default: -maxCValue) - c lower bound; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

inet generator parameters

The inet generator creates IP addresses. Parameters: isUnique (boolean, default: database column uniqueness) - controls uniqueness; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified; ipAddress ('ipv4' | 'ipv6', default: 'ipv4') - type of IP address to generate; includeCidr (boolean, default: true) - determines whether generated IPs include a CIDR suffix.

vector generator parameters

The vector generator creates vectors based on provided parameters. Parameters: isUnique (boolean, default: database column uniqueness) - controls uniqueness; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified; decimalPlaces (number, default: 2) - decimal places for each vector element (e.g., 3 produces 1.123); dimensions (number, default: database column's dimensions) - number of elements in each generated vector (e.g., 3 produces [1,2,3]); minValue (number, default: -1000) - minimum allowed value for each vector element; maxValue (number, default: 1000) - maximum allowed value for each vector element.

seed function refine method example

import { seed } from "drizzle-seed"; await seed(db, schema, { count: 1000 }).refine((funcs) => ({ posts: { columns: { content: funcs.default({ defaultValue: "post content", arraySize: 3 }), }, }, }));

drizzle-seed generators overview

Drizzle-seed provides generator functions for seeding database tables with test data. Generators are used within the seed function's refine() method to define how each column should be populated. Available generators include default, valuesFromArray, intPrimaryKey, number, int, boolean, date, time, timestamp, datetime, year, json, interval, string, uuid, firstName, lastName, fullName, email, phoneNumber, country, city, streetAddress, jobTitle, postcode, state, companyName, loremIpsum, point, line, bitString, inet, and vector.

arraySize with isUnique generates unique values not unique arrays

When both arraySize and isUnique parameters are specified in generators that support them, unique values are generated first and then packed into arrays. This means the array itself is not guaranteed to be unique, only the individual values within it are unique.

default generator parameters

The default generator creates the same given value each time. Parameters: defaultValue (any, required) - the value to generate; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

valuesFromArray generator parameters

The valuesFromArray generator picks values from a provided array. Parameters: values (any[] | {weight: number; values: any[]}[], required) - array of values or array of weighted value objects; isUnique (boolean, default: database column uniqueness) - controls whether generated values are unique; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

intPrimaryKey generator parameters

The intPrimaryKey generator creates sequential integers starting from 1. It takes no parameters.

number generator parameters

The number generator creates floating point numbers within a range. Parameters: isUnique (boolean, default: database column uniqueness) - controls uniqueness; precision (number, default: 100) - decimal precision (10 = one tenth, 100 = one hundredth); maxValue (number, default: precision * 1000 if not unique, precision * count if unique) - upper bound; minValue (number, default: -maxValue) - lower bound; arraySize (number, optional) - creates a one-dimensional array with this many elements if specified.

Give your agent this brain