drizzle-team / drizzle-team/drizzle-orm

[BUG]: drizzle-typebox ignores generatedAlwaysAsIdentity primary keys.

Open
#4,724 5 comments 7 reactions 0 assignees View on GitHub
bug drizzle/typebox priority
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Report hasn't been filed before.

- [x] I have verified that the bug I'm about to report hasn't been filed before.

### What version of `drizzle-orm` are you using?

0.44.2

### What version of `drizzle-kit` are you using?

0.31.4

### Other packages

drizzle-typebox@^0.3.3, @sinclair/typebox@^0.34.33

### Describe the Bug

The `create[Insert|Update|Select]Schema` methods of `drizzle-typebox` ignore primary key columns defined with `generatedAlwaysAsIdentity()`.

The steps to produce it are shown below.

It would be cool if this worked. The workaround that I found is questionable.

```ts
import { sql } from "drizzle-orm";
import { bigint, index, pgTable, text, timestamp } from "drizzle-orm/pg-core";
import {
createInsertSchema,
createUpdateSchema,
createSelectSchema,
} from "drizzle-typebox";
import type { Static } from "@sinclair/typebox";

export const my_table = pgTable(
"my_table",
{
/** NOTE: This field is ignored by drizzle-typebox unless generatedAlwaysAsIdentity is removed! */
id: bigint({ mode: "number" }).primaryKey().generatedAlwaysAsIdentity(),
foo: text().notNull(),
bar: text().notNull(),
baz: text().notNull(),
},
);
// RESULT: The types and schemas defined below are missing the id column.

export const InsertRow = createInsertSchema(app_tokens);
export type InsertRow = Static;

export const UpdateRow = createUpdateSchema(app_tokens);
export type UpdateRow = Static;

export const Row = createSelectSchema(app_tokens);
export type Row = Static;
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.