|
| 1 | +## Bug fixes |
| 2 | + |
| 3 | +- [[BUG]: drizzle seed doesn't work with libSQL](https://github.com/drizzle-team/drizzle-orm/issues/3914) |
| 4 | +- [[BUG]: Seed UUIDs not compatible with Zod/v4](https://github.com/drizzle-team/drizzle-orm/issues/4551) |
| 5 | +- [[BUG]: drizzle seed generates invalid input value (number) for enum strings (pg)](https://github.com/drizzle-team/drizzle-orm/issues/4194) |
| 6 | +- [[BUG]: drizzle seed breaks serial sequence sync with Postgres serial type](https://github.com/drizzle-team/drizzle-orm/issues/3915) |
| 7 | + |
| 8 | +## Features |
| 9 | + |
| 10 | +### ignore column in refinements |
| 11 | + |
| 12 | +Now you can let drizzle-seed know if you want to ignore column during seeding. |
| 13 | + |
| 14 | +```ts |
| 15 | +// schema.ts |
| 16 | +import { integer, pgTable, text } from "drizzle-orm/pg-core"; |
| 17 | + |
| 18 | +export const users = pgTable("users", { |
| 19 | + id: integer().primaryKey(), |
| 20 | + name: text().notNull(), |
| 21 | + age: integer(), |
| 22 | + photo: text(), |
| 23 | +}); |
| 24 | +``` |
| 25 | + |
| 26 | +```ts |
| 27 | +// index.ts |
| 28 | +import { drizzle } from "drizzle-orm/node-postgres"; |
| 29 | +import { seed } from "drizzle-seed"; |
| 30 | +import * as schema from "./schema.ts"; |
| 31 | + |
| 32 | +async function main() { |
| 33 | + const db = drizzle(process.env["DATABASE_URL"]!); |
| 34 | + await seed(db, schema).refine((f) => ({ |
| 35 | + users: { |
| 36 | + count: 5, |
| 37 | + columns: { |
| 38 | + name: f.fullName(), |
| 39 | + photo: false, // the photo column will not be seeded, allowing the database to use its default value. |
| 40 | + }, |
| 41 | + }, |
| 42 | + })); |
| 43 | +} |
| 44 | + |
| 45 | +main(); |
| 46 | +``` |
| 47 | + |
| 48 | +## Improvements |
| 49 | + |
| 50 | +### Added `min`, `max` parameters to `time` generator |
| 51 | + |
| 52 | +```ts |
| 53 | +await seed(db, { timeTable: schema.timeTable }).refine((funcs) => ({ |
| 54 | + timeTable: { |
| 55 | + count, |
| 56 | + columns: { |
| 57 | + time: funcs.time({ |
| 58 | + min: "13:12:13", |
| 59 | + max: "15:12:13", |
| 60 | + }), |
| 61 | + }, |
| 62 | + }, |
| 63 | +})); |
| 64 | +``` |
| 65 | + |
| 66 | +### Added `min`, `max` parameters to `timestamp` generator |
| 67 | + |
| 68 | +```ts |
| 69 | +await seed(db, { timestampTable: schema.timestampTable }).refine((funcs) => ({ |
| 70 | + timestampTable: { |
| 71 | + count, |
| 72 | + columns: { |
| 73 | + timestamp: funcs.timestamp({ |
| 74 | + min: "2025-03-07 13:12:13.123Z", |
| 75 | + max: "2025-03-09 15:12:13.456Z", |
| 76 | + }), |
| 77 | + }, |
| 78 | + }, |
| 79 | +})); |
| 80 | +``` |
| 81 | + |
| 82 | +### Added `min`, `max` parameters to `datetime` generator |
| 83 | + |
| 84 | +```ts |
| 85 | +await seed(db, { datetimeTable: schema.datetimeTable }).refine((funcs) => ({ |
| 86 | + datetimeTable: { |
| 87 | + count, |
| 88 | + columns: { |
| 89 | + datetime: funcs.datetime({ |
| 90 | + min: "2025-03-07 13:12:13Z", |
| 91 | + max: "2025-03-09 15:12:13Z", |
| 92 | + }), |
| 93 | + }, |
| 94 | + }, |
| 95 | +})); |
| 96 | +``` |
| 97 | + |
| 98 | +### PostgreSQL sequences updating after seed |
| 99 | + |
| 100 | +`drizzle-seed` iterates through each column in a table, selects columns of type smallint, integer, bigint, smallserial, serial, or bigserial, and (if a sequence exists) updates it to the column’s maximum seeded value. |
| 101 | + |
| 102 | +```sql |
| 103 | +select setval(pg_get_serial_sequence('"schema_name"."table_name"', 'column_name'), 3, true); |
| 104 | +``` |
| 105 | + |
| 106 | +## Breaking changes |
| 107 | + |
| 108 | +### `uuid` generator was changed and upgraded to v4 |
| 109 | + |
| 110 | +```ts |
| 111 | +await seed(db, { table }).refine((f) => ({ |
| 112 | + table: { |
| 113 | + columns: { |
| 114 | + // AA97B177-9383-4934-8543-0F91A7A02836 |
| 115 | + // ^ |
| 116 | + // 1 |
| 117 | + // the digit at position 1 is always one of '8', '9', 'A' or 'B' |
| 118 | + column1: f.uuid(), |
| 119 | + } |
| 120 | + } |
| 121 | +})) |
| 122 | +``` |
| 123 | + |
| 124 | +**Reason for upgrade** |
| 125 | + |
| 126 | +UUID values generated by the old version of the `uuid` generator fail Zod’s v4 UUID validation. |
| 127 | + |
| 128 | +example |
| 129 | +```ts |
| 130 | +import { createSelectSchema } from 'drizzle-zod'; |
| 131 | +import { seed } from 'drizzle-seed'; |
| 132 | + |
| 133 | +await seed(db, { uuidTest: schema.uuidTest }, { count: 1 }).refine((funcs) => ({ |
| 134 | + uuidTest: { |
| 135 | + columns: { |
| 136 | + col1: funcs.uuid() |
| 137 | + } |
| 138 | + } |
| 139 | + }) |
| 140 | +); |
| 141 | + |
| 142 | +const uuidSelectSchema = createSelectSchema(schema.uuidTest); |
| 143 | +const res = await db.select().from(schema.uuidTest); |
| 144 | +// the line below will throw an error when using old version of uuid generator |
| 145 | +uuidSelectSchema.parse(res[0]); |
| 146 | +``` |
| 147 | + |
| 148 | +**Usage** |
| 149 | +```ts |
| 150 | +await seed(db, schema); |
| 151 | +// or explicit |
| 152 | +await seed(db, schema, { version: '4' }); |
| 153 | +``` |
| 154 | + |
| 155 | +**Switch to the old version** |
| 156 | + |
| 157 | +The previous version of `uuid` generator is v1. |
| 158 | +```ts |
| 159 | +await seed(db, schema, { version: '1' }); |
| 160 | +``` |
| 161 | +To use the v2 generators while maintaining the v1 `uuid` generator: |
| 162 | +```ts |
| 163 | +await seed(db, schema, { version: '2' }); |
| 164 | +``` |
| 165 | +To use the v3 generators while maintaining the v1 `uuid` generator: |
| 166 | +```ts |
| 167 | +await seed(db, schema, { version: '3' }); |
| 168 | +``` |
0 commit comments