Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksiiKH0240 committed Mar 7, 2025
1 parent abdf595 commit 905c951
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 2 deletions.
92 changes: 92 additions & 0 deletions changelogs/drizzle-seed/0.3.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,95 @@ await seed(db, schema);
- https://github.com/drizzle-team/drizzle-orm/issues/4194

drizzle-seed misinterpreted `realEstateTypeEnum` enum as a `real` type.

## Features

- ignore column in refinements

Now you can let drizzle-seed know if you want to ignore column during seeding.

```ts
// schema.ts
import { integer, pgTable, text } from "drizzle-orm/pg-core";

export const users = pgTable("users", {
id: integer().primaryKey(),
name: text().notNull(),
age: integer(),
photo: text(),
});
```

```ts
// index.ts
import { drizzle } from "drizzle-orm/node-postgres";
import { seed } from "drizzle-seed";
import * as schema from "./schema.ts";

async function main() {
const db = drizzle(process.env["DATABASE_URL"]!);
await seed(db, schema).refine((f) => ({
users: {
count: 5,
columns: {
name: f.fullName(),
photo: false, // the photo column will not be seeded, allowing the database to use its default value.
},
},
}));
}

main();
```

## Improvements

- added minTime, maxTime parameters to `time` generator

```ts
await seed(db, { timeTable: schema.timeTable }).refine((funcs) => ({
timeTable: {
count,
columns: {
time: funcs.time({
minTime: "13:12:13",
maxTime: "15:12:13",
}),
},
},
}));
```

- added minTimestamp, maxTimestamp parameters to `timestamp` generator

```ts
await seed(db, { timestampTable: schema.timestampTable }).refine((funcs) => ({
timestampTable: {
count,
columns: {
timestamp: funcs.timestamp({
minTimestamp: "2025-03-07 13:12:13.123Z",
maxTimestamp: "2025-03-09 15:12:13.456Z",
}),
},
},
}));
```

- added minDatetime, maxDatetime parameters to `datetime` generator

```ts
await seed(db, { datetimeTable: schema.datetimeTable }).refine((funcs) => ({
datetimeTable: {
count,
columns: {
datetime: funcs.datetime({
minDatetime: "2025-03-07 13:12:13Z",
maxDatetime: "2025-03-09 15:12:13Z",
}),
},
},
}));
```

- exported `AbstractGenerator` so that users can build their own custom generator classes.
1 change: 0 additions & 1 deletion drizzle-seed/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import type { RefinementsType } from './types/seedService.ts';
import type { Column, Relation, RelationWithReferences, Table } from './types/tables.ts';

export { AbstractGenerator } from './services/Generators.ts';
export { CustomGenerator } from './services/Generators.ts';

type InferCallbackType<
DB extends
Expand Down
2 changes: 1 addition & 1 deletion drizzle-seed/tests/mysql/generatorsTest/generators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ afterAll(async () => {

const count = 10000;

test.only('datetime generator test', async () => {
test('datetime generator test', async () => {
await seed(db, { datetimeTable: schema.datetimeTable }).refine((funcs) => ({
datetimeTable: {
count,
Expand Down

0 comments on commit 905c951

Please sign in to comment.