drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.2k stars 617 forks source link

[BUG]: `Do not know how to serialize a BigInt` errors when using BigInt in `default(0n)` directive #1879

Open mimamuh opened 8 months ago

mimamuh commented 8 months ago

What version of drizzle-orm are you using?

0.29.3

What version of drizzle-kit are you using?

0.20.14

Describe the Bug

  1. I have a schema.ts file where I have a value of type BigInt with a .default(0n) directive.
  2. When I want to run a drizzle-kit command like drizzle-kit generate:pg, it causes an Do not know how to serialize a BigInt error.

Schema

export const myTable = pgTable('my_table', {
  id: bigserial('id', { mode: 'bigint' }).primaryKey(),
  value: bigint('value', {
    mode: 'bigint',
  })
    .notNull()
    .default(0n), // <- causes the error
});

Error

Reading config file '.../drizzle.config.ts'
TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)
    at applyJsonDiff (.../node_modules/drizzle-kit/bin.cjs:5429:27)
    at applySnapshotsDiff (.../node_modules/drizzle-kit/bin.cjs:17397:20)
    at prepareSQL (.../node_modules/drizzle-kit/bin.cjs:15055:20)
    at prepareAndMigratePg (.../node_modules/drizzle-kit/bin.cjs:14834:48)
    at async Command.<anonymous> (.../node_modules/drizzle-kit/bin.cjs:63024:3)

Expected behavior

Know how to seriazile BigInt values in .default(...) directive.

Environment & setup

No response

vimtor commented 5 months ago

As a workaround:

export const myTable = pgTable('my_table', {
  id: bigserial('id', { mode: 'bigint' }).primaryKey(),
  value: bigint('value', {
    mode: 'bigint',
  })
    .notNull()
    .default(sql`0::bigint`), // <- causes the error
});