|
| 1 | +## Bug fixes |
| 2 | + |
| 3 | +- https://github.com/drizzle-team/drizzle-orm/issues/3644 |
| 4 | +- seeding a table with columns that have .default(sql``) will result in an error |
| 5 | + |
| 6 | +## Features |
| 7 | + |
| 8 | +- added support for postgres uuid columns |
| 9 | + |
| 10 | +Example |
| 11 | + |
| 12 | +```ts |
| 13 | +import { pgTable, uuid } from "drizzle-orm/pg-core"; |
| 14 | +import { drizzle } from "drizzle-orm/node-postgres"; |
| 15 | +import { seed } from "drizzle-seed"; |
| 16 | + |
| 17 | +const users = pgTable("users", { |
| 18 | + uuid: uuid("uuid"), |
| 19 | +}); |
| 20 | + |
| 21 | +async function main() { |
| 22 | + const db = drizzle(process.env.DATABASE_URL!); |
| 23 | + // You can let it seed automatically |
| 24 | + // await seed(db, { users }); |
| 25 | + |
| 26 | + // Alternatively, you can manually specify the generator in refine. |
| 27 | + await seed(db, { users }, { count: 1000 }).refine((funcs) => ({ |
| 28 | + users: { |
| 29 | + columns: { |
| 30 | + uuid: funcs.uuid(), |
| 31 | + }, |
| 32 | + }, |
| 33 | + })); |
| 34 | +} |
| 35 | + |
| 36 | +main(); |
| 37 | +``` |
| 38 | + |
| 39 | +## |
| 40 | + |
| 41 | +- added support for postgres array columns |
| 42 | + |
| 43 | +Example |
| 44 | + |
| 45 | +```ts |
| 46 | +import { pgTable, integer, text, varchar } from "drizzle-orm/pg-core"; |
| 47 | +import { drizzle } from "drizzle-orm/node-postgres"; |
| 48 | +import { seed } from "drizzle-seed"; |
| 49 | + |
| 50 | +const users = pgTable("users", { |
| 51 | + id: integer().primaryKey(), |
| 52 | + name: text().notNull(), |
| 53 | + phone_numbers: varchar({ length: 256 }).array(), |
| 54 | +}); |
| 55 | +``` |
| 56 | + |
| 57 | +You can specify the `arraySize` parameter in generator options, like `funcs.phoneNumber({ arraySize: 3 })`, to generate 1D arrays. |
| 58 | + |
| 59 | +```ts |
| 60 | +async function main() { |
| 61 | + const db = drizzle(process.env.DATABASE_URL!); |
| 62 | + await seed(db, { users }, { count: 1000 }).refine((funcs) => ({ |
| 63 | + users: { |
| 64 | + columns: { |
| 65 | + phone_numbers: funcs.phoneNumber({ arraySize: 3 }), |
| 66 | + }, |
| 67 | + }, |
| 68 | + })); |
| 69 | +} |
| 70 | + |
| 71 | +main(); |
| 72 | +``` |
| 73 | + |
| 74 | +Alternatively, you can let it seed automatically, and it will handle arrays of any dimension. |
| 75 | + |
| 76 | +```ts |
| 77 | +async function main() { |
| 78 | + const db = drizzle(process.env.DATABASE_URL!); |
| 79 | + await seed(db, { users }); |
| 80 | +} |
| 81 | + |
| 82 | +main(); |
| 83 | +``` |
| 84 | + |
| 85 | +## |
| 86 | + |
| 87 | +- added support for cyclic tables |
| 88 | + |
| 89 | +You can now seed tables with cyclic relations. |
| 90 | + |
| 91 | +```ts |
| 92 | +import type { AnyPgColumn } from "drizzle-orm/pg-core"; |
| 93 | +import { |
| 94 | + foreignKey, |
| 95 | + integer, |
| 96 | + pgTable, |
| 97 | + serial, |
| 98 | + varchar, |
| 99 | +} from "drizzle-orm/pg-core"; |
| 100 | + |
| 101 | +export const modelTable = pgTable( |
| 102 | + "model", |
| 103 | + { |
| 104 | + id: serial().primaryKey(), |
| 105 | + name: varchar().notNull(), |
| 106 | + defaultImageId: integer(), |
| 107 | + }, |
| 108 | + (t) => [ |
| 109 | + foreignKey({ |
| 110 | + columns: [t.defaultImageId], |
| 111 | + foreignColumns: [modelImageTable.id], |
| 112 | + }), |
| 113 | + ] |
| 114 | +); |
| 115 | + |
| 116 | +export const modelImageTable = pgTable("model_image", { |
| 117 | + id: serial().primaryKey(), |
| 118 | + url: varchar().notNull(), |
| 119 | + caption: varchar(), |
| 120 | + modelId: integer() |
| 121 | + .notNull() |
| 122 | + .references((): AnyPgColumn => modelTable.id), |
| 123 | +}); |
| 124 | + |
| 125 | +async function main() { |
| 126 | + const db = drizzle(process.env.DATABASE_URL!); |
| 127 | + await seed(db, { modelTable, modelImageTable }); |
| 128 | +} |
| 129 | + |
| 130 | +main(); |
| 131 | +``` |
0 commit comments