drizzle-team / drizzle-team/drizzle-orm

[BUG]: Xata drizzle-kit push zod validation error

Open
#4,132 0 comments 0 reactions 0 assignees View on GitHub
bug db/postgres driver/xata drizzle/kit drizzle/zod 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.39.3

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

0.30.4

### Other packages

drizzle-zod@0.7.0

### Describe the Bug

I have schemas defined via TypeScript, specifically using the following for my `id` columns:
```ts
id: integer().primaryKey().generatedAlwaysAsIdentity(),
```

Initial call to `drizzle-kit push` to an empty Xata database works fine, it fails with the following error on all subsequent calls:
```bash
_ZodError: [
{
"code": "invalid_type",
"expected": "string",
"received": "number",
"path": [
"tables",
"public.blobs",
"columns",
"id",
"identity",
"name"
],
"message": "Expected string, received number"
},
```

This is related to parsing the remote schema here: https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-kit/src/serializer/pgSchema.ts#L140 and could be vaguely related to https://github.com/drizzle-team/drizzle-orm/issues/2919

The issue stems from the fact that even though Drizzle generates the proper sequence names (i.e. `blobs_id_seq`) which can be seen in Xata's schema history, Xata seems to ignore them behind the scenes and generates them as numbers (i.e. `6088102`) which in hand is parsed as a number.

I was able to fix this by changing the above zod validation to `name: string({ coerce: true })`

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.