Skip to content

fix: map drizzle PgNumeric to zero number by default - #129

Closed
miguelrk wants to merge 2 commits into
rocicorp:mainfrom
miguelrk:fix-numeric-defaults
Closed

fix: map drizzle PgNumeric to zero number by default#129
miguelrk wants to merge 2 commits into
rocicorp:mainfrom
miguelrk:fix-numeric-defaults

Conversation

@miguelrk

@miguelrk miguelrk commented Jul 9, 2025

Copy link
Copy Markdown

This PR corrects how Drizzle ORM's PgNumeric column type is mapped in our Zero schema.

Previously, PgNumeric was mapped to number, while Drizzle ORM defaults to handling .numeric() and .decimal() (another alias) types as strings. This is a deliberate design choice to prevent precision loss. By keeping the values as strings, their exact representation from the database is maintained.

The fix updates the mapping in drizzleColumnTypeToZeroType to:

- PgNumeric: "number",
+ PgNumeric: "string",

Would appreciate a patch release!

@miguelrk
miguelrk marked this pull request as draft July 9, 2025 21:07
@0xcadams

Copy link
Copy Markdown
Member

If you want this, I would recommend using the custom config w/ drizzle-zero.config.ts and overriding that way. Zero by default expects number for all numeric types. I don't want to override that default but understand the reasoning here.

export default drizzleZeroConfig(drizzleSchema, {
  tables: {
    user: {
      id: true,
      name: true,
      // use string() here to override
      numeric: string(),
    },
  }
});

@miguelrk miguelrk closed this Jul 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants