Versioning

drizzle-seed uses versioning to manage outputs for static and dynamic data. To ensure true determinism, ensure that values remain unchanged when using the same seed number. If changes are made to static data sources or dynamic data generation logic, the version will be updated, allowing you to choose between sticking with the previous version or using the latest.

You can upgrade to the latest drizzle-seed version for new features, such as additional generators, while maintaining deterministic outputs with a previous version if needed. This is particularly useful when you need to rely on existing deterministic data while accessing new functionality.

await seed(db, schema, { version: '2' });

History

api versionnpm versionChanged generators
v10.1.1
v20.2.1string(), interval({ isUnique: true })
v30.4.0hash generating function
v4 (LTS) 1.0.0-beta.8uuid

How it works under the hood?

This is not an actual API change; it is just an example of how we will proceed with drizzle-seed versioning.

For example, lastName generator was changed, and new version, V2, of this generator became available.

Later, firstName generator was changed, making V3 version of this generator available.

V1V2V3(latest)
LastNameGenLastNameGenV1LastNameGenV2
FirstNameGenFirstNameGenV1FirstNameGenV3
Use the firstName generator of version 3 and the lastName generator of version 2
await seed(db, schema);

If you are not ready to use latest generator version right away, you can specify max version to use

Use the firstName generator of version 1 and the lastName generator of version 2
await seed(db, schema, { version: '2' });
Use the firstName generator of version 1 and the lastName generator of version 1.
await seed(db, schema, { version: '1' });

Version 2

Unique interval generator was changed

Reason for upgrade

An older version of the generator could produce intervals like 1 minute 60 seconds and 2 minutes 0 seconds, treating them as distinct intervals. However, when the 1 minute 60 seconds interval is inserted into a SQLite database, it is automatically converted to 2 minutes 0 seconds. As a result, attempting to insert the 2 minutes 0 seconds interval into a unique column afterwards will cause an error

You will be affected, if you use the unique interval generator in your seeding script, as shown in the script below:

import { blob, sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { drizzle } from 'drizzle-orm/better-sqlite3';
import { seed } from 'drizzle-seed';

const intervals = sqliteTable('intervals', {
	interval1: text().unique(),
	interval2: text(),
	interval3: blob().unique(),
	interval4: blob(),
});

async function main() {
	const db = drizzle(process.env.DATABASE_URL!);

	await seed(db, { intervals }).refine((f) => ({
		intervals: {
			columns: {
				interval1: f.interval({ isUnique: true }),
				interval2: f.interval({ isUnique: true }),
				interval3: f.interval({ isUnique: true }),
				interval4: f.interval({ isUnique: true }),
			},
		},
	}));
}

main();

string generators were changed: both non-unique and unique

Reason to upgrade

Ability to generate a unique string based on the length of the text column (e.g., varchar(20))

You will be affected, if your table includes a column of a text-like type with a maximum length parameter or a unique column of a text-like type:

import { drizzle } from 'drizzle-orm/better-sqlite3';
import { blob, sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { seed } from "drizzle-seed";

const strings = sqliteTable('strings', {
	string1: text().unique(),
	string2: text({ length: 256 }),
	string3: text({ length: 256 }).unique(),
	string4: blob().unique(),
});

async function main() {
  const db = drizzle(process.env.DATABASE_URL!);

  await seed(db, { strings });
}

main();

You will be affected, if you use the string generator in your seeding script, as shown in the script below:

import { blob, sqliteTable, text } from 'drizzle-orm/sqlite-core';
import { drizzle } from 'drizzle-orm/better-sqlite3';
import { seed } from "drizzle-seed";

const strings = sqliteTable("strings", {
    string1: text().unique(),
	string2: text(),
	string3: text({ length: 256 }).unique(),
	string4: text({ length: 256 }),
	string5: text({ length: 256 }),
	string6: blob().unique(),
	string7: blob(),
});

async function main() {
	const db = drizzle(process.env.DATABASE_URL!);

	await seed(db, { strings }).refine((f) => ({
		strings: {
			columns: {
				string1: f.string({ isUnique: true }),
				string2: f.string({ isUnique: true }),
				string3: f.string({ isUnique: true }),
				string4: f.string({ isUnique: true }),
				string5: f.string(),
				string6: f.string({ isUnique: true }),
				string7: f.string({ isUnique: true }),
			},
		},
	}));
}

main();

Version 3

hash generating function was changed

Reason to upgrade

The previous version of the hash generating function generated different hashes depending on whether Bun or Node.js was used, and hashes also varied across versions of Node.js.

The new hash generating function will generate the same hash regardless of the version of Node.js or Bun, resulting in deterministic data generation across all versions.

All generators will output different values compared to the previous version, even with the same seed number.

Usage

await seed(db, schema);
// or explicit
await seed(db, schema, { version: '3' });

Switch to the old version

The previous version of hash generating function is v1.

await seed(db, schema, { version: '1' });

To use the v2 generators while maintaining the v1 hash generating function:

await seed(db, schema, { version: '2' });

Version 4

uuid generator was changed

Reason to upgrade

UUID values generated by the old version of the uuid generator fail Zod’s v4 UUID validation.

example

import { createSelectSchema } from 'drizzle-zod';
import { seed } from 'drizzle-seed';

await seed(db, { uuidTest: schema.uuidTest }, { count: 1 }).refine((funcs) => ({
		uuidTest: {
			columns: {
				col1: funcs.uuid()
			}
		}
	})
);

const uuidSelectSchema = createSelectSchema(schema.uuidTest);
const res = await db.select().from(schema.uuidTest);
// the line below will throw an error when using old version of uuid generator
uuidSelectSchema.parse(res[0]);

Usage

await seed(db, schema);
// or explicit
await seed(db, schema, { version: '4' });

Switch to the old version

The previous version of uuid generator is v1.

await seed(db, schema, { version: '1' });

To use the v2 generators while maintaining the v1 uuid generator:

await seed(db, schema, { version: '2' });

To use the v3 generators while maintaining the v1 uuid generator:

await seed(db, schema, { version: '3' });