Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/beta' into fix-validators
Browse files Browse the repository at this point in the history
  • Loading branch information
L-Mario564 committed Dec 11, 2024
2 parents 7af7983 + a4fb988 commit 01ed42f
Show file tree
Hide file tree
Showing 60 changed files with 4,208 additions and 697 deletions.
131 changes: 131 additions & 0 deletions changelogs/drizzle-seed/0.1.3.md
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();
```
3 changes: 2 additions & 1 deletion drizzle-orm/src/mysql-core/query-builders/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export type MySqlUpdateSetSource<TTable extends MySqlTable> =
& {
[Key in keyof TTable['$inferInsert']]?:
| GetColumnData<TTable['_']['columns'][Key], 'query'>
| SQL;
| SQL
| undefined;
}
& {};

Expand Down
3 changes: 2 additions & 1 deletion drizzle-orm/src/pg-core/query-builders/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export type PgUpdateSetSource<TTable extends PgTable> =
[Key in keyof TTable['$inferInsert']]?:
| GetColumnData<TTable['_']['columns'][Key]>
| SQL
| PgColumn;
| PgColumn
| undefined;
}
& {};

Expand Down
43 changes: 25 additions & 18 deletions drizzle-orm/src/relations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,27 @@ export type DBQueryConfig<
TTableConfig extends TableRelationalConfig = TableRelationalConfig,
> =
& {
columns?: {
[K in keyof TTableConfig['columns']]?: boolean;
};
with?: {
[K in keyof TTableConfig['relations']]?:
| true
| DBQueryConfig<
TTableConfig['relations'][K] extends One ? 'one' : 'many',
false,
TSchema,
FindTableByDBName<
columns?:
| {
[K in keyof TTableConfig['columns']]?: boolean;
}
| undefined;
with?:
| {
[K in keyof TTableConfig['relations']]?:
| true
| DBQueryConfig<
TTableConfig['relations'][K] extends One ? 'one' : 'many',
false,
TSchema,
TTableConfig['relations'][K]['referencedTableName']
FindTableByDBName<
TSchema,
TTableConfig['relations'][K]['referencedTableName']
>
>
>;
};
| undefined;
}
| undefined;
extras?:
| Record<string, SQL.Aliased>
| ((
Expand All @@ -238,7 +243,8 @@ export type DBQueryConfig<
: TTableConfig['columns']
>,
operators: { sql: Operators['sql'] },
) => Record<string, SQL.Aliased>);
) => Record<string, SQL.Aliased>)
| undefined;
}
& (TRelationType extends 'many' ?
& {
Expand All @@ -260,11 +266,12 @@ export type DBQueryConfig<
: TTableConfig['columns']
>,
operators: OrderByOperators,
) => ValueOrArray<AnyColumn | SQL>);
limit?: number | Placeholder;
) => ValueOrArray<AnyColumn | SQL>)
| undefined;
limit?: number | Placeholder | undefined;
}
& (TIsRoot extends true ? {
offset?: number | Placeholder;
offset?: number | Placeholder | undefined;
}
: {})
: {});
Expand Down
3 changes: 2 additions & 1 deletion drizzle-orm/src/singlestore-core/query-builders/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export type SingleStoreUpdateSetSource<TTable extends SingleStoreTable> =
& {
[Key in keyof TTable['$inferInsert']]?:
| GetColumnData<TTable['_']['columns'][Key], 'query'>
| SQL;
| SQL
| undefined;
}
& {};

Expand Down
3 changes: 2 additions & 1 deletion drizzle-orm/src/sqlite-core/query-builders/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export type SQLiteUpdateSetSource<TTable extends SQLiteTable> =
[Key in keyof TTable['$inferInsert']]?:
| GetColumnData<TTable['_']['columns'][Key], 'query'>
| SQL
| SQLiteColumn;
| SQLiteColumn
| undefined;
}
& {};

Expand Down
2 changes: 1 addition & 1 deletion drizzle-orm/src/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export type InferModelFromColumns<
TColumns[Key],
TConfig['override']
>
]?: GetColumnData<TColumns[Key], 'query'>;
]?: GetColumnData<TColumns[Key], 'query'> | undefined;
}
: {
[
Expand Down
6 changes: 3 additions & 3 deletions drizzle-seed/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "drizzle-seed",
"version": "0.1.2",
"version": "0.1.3",
"main": "index.js",
"type": "module",
"scripts": {
"build": "tsx scripts/build.ts",
"pack": "(cd dist && npm pack --pack-destination ..) && rm -f package.tgz && mv *.tgz package.tgz",
"test": "vitest --config ./src/tests/vitest.config.ts",
"test:types": "cd src/type-tests && tsc",
"test": "vitest --config ./vitest.config.ts",
"test:types": "cd type-tests && tsc",
"generate-for-tests:pg": "drizzle-kit generate --config=./src/tests/pg/drizzle.config.ts",
"generate-for-tests:mysql": "drizzle-kit generate --config=./src/tests/mysql/drizzle.config.ts",
"generate-for-tests:sqlite": "drizzle-kit generate --config=./src/tests/sqlite/drizzle.config.ts",
Expand Down
Loading

0 comments on commit 01ed42f

Please sign in to comment.