changelogs/drizzle-seed/0.2.1.md
We are introducing a new parameter, version, to the seed function options. This parameter, which controls generator versioning, has been added to make it easier to update deterministic generators in the future. Since values should remain consistent after each regeneration, it is crucial to provide a well-designed API for gradual updates
await seed(db, schema, { version: '2' });
This is not an actual API change; it is just an example of how we will proceed with
drizzle-seedversioning
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.
V1 | V2 | V3(latest) | |
|---|---|---|---|
| LastNameGen | LastNameGenV1 | LastNameGenV2 | |
| FirstNameGen | FirstNameGenV1 | FirstNameGenV3 |
firstName generator of version 3 and the lastName generator of version 2await seed(db, schema);
If you are not ready to use latest generator version right away, you can specify max version to use
firstName generator of version 1 and the lastName generator of version 2await seed(db, schema, { version: '2' });
firstName generator of version 1 and the lastName generator of version 1.await seed(db, schema, { version: '1' });
Each update with breaking changes for generators will be documented on our docs and in release notes, explaining which version you should use, if you are not ready to upgrade the way generators works
interval unique generator was changed and upgraded to v2await seed(db, { table }).refine((f) => ({
table: {
columns: {
// this function usage will output different values with the same `seed` number from previous version
column1: f.interval({ isUnique: true }),
}
}
}))
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 PostgreSQL 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
Usage
await seed(db, schema);
// or explicit
await seed(db, schema, { version: '2' });
Switch to the old version
await seed(db, schema, { version: '1' });
string generators were changed and upgraded to v2await seed(db, { table }).refine((f) => ({
table: {
columns: {
// this function will output different values with the same `seed` number from previous version
column1: f.string(),
}
}
}))
Reason to upgrade
Ability to generate a unique string based on the length of the text column (e.g., varchar(20))
Default generators for text, varchar, char will output different values with the same seed number from previous version.
// schema.ts
import * as p from 'drizzle-orm/pg-core'
export const table = p.pgTable('table', {
column1: p.text(),
column2: p.varchar(),
column3: p.char()
});
// index.ts
...
// this will be affected with new changes
await seed(db, { table });
Switch to the old version
await seed(db, schema, { version: '' });
Default generators for text, char, varchar, binary, varbinary will output different values with the same seed number.
// schema.ts
import * as p from 'drizzle-orm/mysql-core'
export const table = p.mysqlTable('table', {
column1: p.text(),
column2: p.char(),
column3: p.varchar({ length: 256 }),
column4: p.binary(),
column5: p.varbinary({ length: 256 }),
});
// index.ts
...
// this will be affected with new changes
await seed(db, {table})
Switch to the old version
await seed(db, schema, { version: '1' });
Default generators for text, numeric, blob, blobbuffer will output different values with the same seed number.
// schema.ts
import * as p from 'drizzle-orm/sqlite-core'
export const table = p.sqliteTable('table', {
column1: p.text(),
column2: p.numeric(),
column3: p.blob({ mode:'buffer' }),
column4: p.blob(),
});
// index.ts
...
// this will be affected with new changes
await seed(db, { table })