forked from drizzle-team/drizzle-orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/beta' into fix-validators
- Loading branch information
Showing
60 changed files
with
4,208 additions
and
697 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
## Bug fixes | ||
|
||
- https://github.com/drizzle-team/drizzle-orm/issues/3644 | ||
- seeding a table with columns that have .default(sql``) will result in an error | ||
|
||
## Features | ||
|
||
- added support for postgres uuid columns | ||
|
||
Example | ||
|
||
```ts | ||
import { pgTable, uuid } from "drizzle-orm/pg-core"; | ||
import { drizzle } from "drizzle-orm/node-postgres"; | ||
import { seed } from "drizzle-seed"; | ||
|
||
const users = pgTable("users", { | ||
uuid: uuid("uuid"), | ||
}); | ||
|
||
async function main() { | ||
const db = drizzle(process.env.DATABASE_URL!); | ||
// You can let it seed automatically | ||
// await seed(db, { users }); | ||
|
||
// Alternatively, you can manually specify the generator in refine. | ||
await seed(db, { users }, { count: 1000 }).refine((funcs) => ({ | ||
users: { | ||
columns: { | ||
uuid: funcs.uuid(), | ||
}, | ||
}, | ||
})); | ||
} | ||
|
||
main(); | ||
``` | ||
|
||
## | ||
|
||
- added support for postgres array columns | ||
|
||
Example | ||
|
||
```ts | ||
import { pgTable, integer, text, varchar } 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(), | ||
phone_numbers: varchar({ length: 256 }).array(), | ||
}); | ||
``` | ||
|
||
You can specify the `arraySize` parameter in generator options, like `funcs.phoneNumber({ arraySize: 3 })`, to generate 1D arrays. | ||
|
||
```ts | ||
async function main() { | ||
const db = drizzle(process.env.DATABASE_URL!); | ||
await seed(db, { users }, { count: 1000 }).refine((funcs) => ({ | ||
users: { | ||
columns: { | ||
phone_numbers: funcs.phoneNumber({ arraySize: 3 }), | ||
}, | ||
}, | ||
})); | ||
} | ||
|
||
main(); | ||
``` | ||
|
||
Alternatively, you can let it seed automatically, and it will handle arrays of any dimension. | ||
|
||
```ts | ||
async function main() { | ||
const db = drizzle(process.env.DATABASE_URL!); | ||
await seed(db, { users }); | ||
} | ||
|
||
main(); | ||
``` | ||
|
||
## | ||
|
||
- added support for cyclic tables | ||
|
||
You can now seed tables with cyclic relations. | ||
|
||
```ts | ||
import type { AnyPgColumn } from "drizzle-orm/pg-core"; | ||
import { | ||
foreignKey, | ||
integer, | ||
pgTable, | ||
serial, | ||
varchar, | ||
} from "drizzle-orm/pg-core"; | ||
|
||
export const modelTable = pgTable( | ||
"model", | ||
{ | ||
id: serial().primaryKey(), | ||
name: varchar().notNull(), | ||
defaultImageId: integer(), | ||
}, | ||
(t) => [ | ||
foreignKey({ | ||
columns: [t.defaultImageId], | ||
foreignColumns: [modelImageTable.id], | ||
}), | ||
] | ||
); | ||
|
||
export const modelImageTable = pgTable("model_image", { | ||
id: serial().primaryKey(), | ||
url: varchar().notNull(), | ||
caption: varchar(), | ||
modelId: integer() | ||
.notNull() | ||
.references((): AnyPgColumn => modelTable.id), | ||
}); | ||
|
||
async function main() { | ||
const db = drizzle(process.env.DATABASE_URL!); | ||
await seed(db, { modelTable, modelImageTable }); | ||
} | ||
|
||
main(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.