Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Pushing a table with a fixed array will fail on certain conditions (drizzle-orm/pg-core) #3582

Open
1 task done
vignedev opened this issue Nov 19, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@vignedev
Copy link

vignedev commented Nov 19, 2024

Report hasn't been filed before.

  • 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.36.3

What version of drizzle-kit are you using?

^0.28.1

Other packages

tsx@4.19.2

Describe the Bug

Apolgies if this has been reported, as I couldn't find it. Using PostgreSQL, and node-postgres with drizzle. Specifying the schema as such:

import { pgTable, serial, real } from 'drizzle-orm/pg-core'

export const testTable = pgTable('test_table', {
  testId: serial('test_id').primaryKey().notNull(),
  bbox: real('bbox').array(4) // <-- desired fixed size
})

...and pushing it with npx drizzle-kit push will succeed. However, if I insert anything with the following snippet:

import { drizzle } from 'drizzle-orm/node-postgres'
import * as schema from './schema'

const db = drizzle(process.env['POSTGRESQL_DB'], { schema })
db.insert(schema.testTable).values({
  bbox: [0, 1, 2, 3]
}).then(console.log)

...and later try npx drizzle-kit push, I will get the following:

$ npx drizzle-kit push

No config path provided, using default 'drizzle.config.ts'
Reading config file '/home/vignette/Projects/drizzle-bugreport/drizzle.config.ts'
Using 'pg' driver for database querying
[✓] Pulling schema from database...
 Warning  Found data-loss statements:
· You're about to change bbox column type from real[] to real[4] with 1 items

THIS ACTION WILL CAUSE DATA LOSS AND CANNOT BE REVERTED

Do you still want to push changes?
[x] All changes were aborted

More over, the pulled schema does not contain the array size restrictions. Here's the output of npx drizzle-kit pull's schema.ts:

import { pgTable, serial, real } from "drizzle-orm/pg-core"
import { sql } from "drizzle-orm"



export const testTable = pgTable("test_table", {
	testId: serial("test_id").primaryKey().notNull(),
	bbox: real().array(),
});
@vignedev vignedev added the bug Something isn't working label Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant