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 · PostgreSQL · all subjects

drizzle-seed

28 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

drizzle-seed v3 output differs from v2

All generators output different values in version 3 compared to version 2, even with the same seed number, due to the changed hash generating function.

drizzle-seed v4 uuid generator change

In version 4, the uuid generator was changed because the previous version generated UUID values that failed Zod's v4 UUID validation. Version 4 generates valid v4 UUIDs that pass Zod validation.

drizzle-seed version backwards compatibility example

To use v2 generators while maintaining the v1 hash generating function: `await seed(db, schema, { version: '2' });`. To use v3 generators while maintaining the v1 uuid generator: `await seed(db, schema, { version: '3' });`

drizzle-seed version parameter syntax

To specify a drizzle-seed version, use the version option in the seed function: `await seed(db, schema, { version: '2' });`

drizzle-seed version history

Version history: v1 (npm 0.1.1) - baseline; 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.

drizzle-seed v2 unique interval generator change

In version 2, the unique interval generator was changed because the previous version could produce intervals like '1 minute 60 seconds' that are distinct in generation but get normalized by PostgreSQL to '2 minutes 0 seconds' on insertion, causing unique constraint violations. Version 2 fixes this by generating properly normalized intervals.

drizzle-seed v2 string generator change

In version 2, string generators (both unique and non-unique) were changed to generate unique strings based on the length of the text column (e.g., varchar(20)). This affects columns with text-like types that have a maximum length parameter or unique columns of text-like types.

drizzle-seed v3 hash generating function change

In version 3, the hash generating function was changed to generate the same hash regardless of Node.js or Bun version, ensuring deterministic data generation across all versions. The previous version generated different hashes depending on whether Bun or Node.js was used and varied across Node.js versions.

drizzle-seed versioning system

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

drizzle-seed: with property only works for one-to-many relationships

The with option in drizzle-seed works only for one-to-many relationships. For example, you can use users with posts (one user has many posts), but you cannot use posts with users (many posts have one user). Due to TypeScript limitations with circular dependencies, the with option will display all tables in the schema and you must manually select the one with the one-to-many relationship.

drizzle-seed: composite unique constraint limitations

Seeding is not supported when two composite unique constraints share a column. However, this is allowed if one of the constraints is a single-column unique constraint. Additionally, you cannot use a generator that doesn't expose an isUnique option in its config unless it's one of the always-unique generators: intPrimaryKey, email, phoneNumber, or uuid.

drizzle-seed: basic usage with seed function

Example: import { pgTable, integer, text } from "drizzle-orm/pg-core"; import { drizzle } from "drizzle-orm/node-postgres"; import { seed } from "drizzle-seed"; const users = pgTable("users", { id: integer().primaryKey(), name: text().notNull(), }); async function main() { const db = drizzle(process.env.DATABASE_URL!); await seed(db, { users }); } main();

drizzle-seed: reset database example

Example: import * as schema from "./schema.ts"; import { reset } from "drizzle-seed"; async function main() { const db = drizzle(process.env.DATABASE_URL!); await reset(db, schema); } main();

drizzle-seed: refine API basic syntax

Example: await seed(db, schema).refine((f) => ({ users: { columns: {}, count: 10, with: { posts: 10 } } } ));

drizzle-seed: refine column with generator function example

Example: await seed(db, { users: schema.users }).refine((f) => ({ users: { columns: { name: f.fullName() }, count: 20 } } ));

drizzle-seed: exclude column from seeding with false

Example: await seed(db, { users: schema.users }).refine((f) => ({ users: { columns: { name: false } } } )); Setting a column to false prevents it from being seeded, allowing the database to use its default value.

drizzle-seed: seed with relationships using with property

Example: await seed(db, schema).refine((f) => ({ users: { count: 20, with: { posts: 10 } } } )); This seeds 20 users with 10 posts created for each user.

drizzle-seed: int generator with minValue, maxValue, and isUnique

Example: f.int({ minValue: 10000, maxValue: 20000, isUnique: true }) generates unique integers between 10000 and 20000.

drizzle-seed: valuesFromArray generator

Example: f.valuesFromArray({ values: ["The sun set behind the mountains...", "I can't believe...", "Sometimes, all you need..."] }) selects values from a custom array of predefined strings.

drizzle-seed: available generator functions

drizzle-seed provides generator functions accessible via the funcs parameter in refine callback, including: fullName, firstName, lastName, companyName, jobTitle, streetAddress, city, state, country, postcode, phoneNumber (with template option), date (with minDate and maxDate), loremIpsum, int, number (with precision), email, uuid, valuesFromArray, weightedRandom, and default.

drizzle-seed: deterministic fake data generation library

drizzle-seed is a TypeScript library that generates deterministic, realistic fake data to populate databases using a seedable pseudorandom number generator (pRNG). The same seed number always produces the same sequence of fake data, enabling consistent and reproducible data sets across different runs. This is useful for testing, development, and debugging.

drizzle-seed: default entity count

By default, the seed function creates 10 entities. This can be overridden by specifying a count value in the seed options object.

drizzle-seed: seed option for reproducible data

The seed option in drizzle-seed allows you to specify a different number to generate a unique set of values. Each new number will generate a different set of values for subsequent runs.

drizzle-seed: reset database with TRUNCATE CASCADE

The reset function from drizzle-seed allows you to easily reset your database and seed it with new values. For PostgreSQL, drizzle-seed generates TRUNCATE statements with the CASCADE option to ensure all tables are empty: TRUNCATE tableName1, tableName2, ... CASCADE;

drizzle-seed: refine API for custom seeding behavior

The refine callback in drizzle-seed receives a list of all available generator functions and should return an object with keys representing tables you want to refine. Each table can specify: columns (refine default behavior or exclude with false), count (number of rows to insert, overrides global count), and with (number of referenced entities to create for one-to-many relationships).

drizzle-seed: weighted random for columns and with property

drizzle-seed provides weighted random API for two use cases: (1) columns inside table refinements, where you can specify multiple datasets with different priority, and (2) the with property, determining the amount of related entities to be created with weighted distributions.

drizzle-seed: weighted random syntax for columns

To use weighted random for a column, call f.weightedRandom() with an array of objects, each containing a weight (0-1, representing percentage chance) and a value (the generator function or constant to use): f.weightedRandom([{weight: 0.3, value: funcs.int({minValue: 10, maxValue: 100})}, {weight: 0.7, value: funcs.number({minValue: 100, maxValue: 300, precision: 100})}])

drizzle-seed: weighted random syntax for with property

To use weighted random for the with property determining related entity counts, specify an array of objects with weight and count (either a number or array of numbers representing range): {weight: 0.6, count: [1, 2, 3]}, {weight: 0.3, count: [5, 6, 7]}, {weight: 0.1, count: [8, 9, 10]}

Give your agent this brain