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
21.57k stars 490 forks source link

[BUG]: generate with pg_vector - migration produce misspelled string #2328

Open vgauthier opened 1 month ago

vgauthier commented 1 month ago

What version of drizzle-orm are you using?

0.30.10

What version of drizzle-kit are you using?

No response

Describe the Bug

When using pg_vector extension the migration generate the following update.

ALTER TABLE "publications" ADD COLUMN "embedding" "vector(512)";

instead of

ALTER TABLE "publications" ADD COLUMN "embedding" vector(512); <= without quote on vector

produce the following error:

PostgresError: type "vector(512)" does not exist
    at ErrorResponse (/Users/vgauthier/Documents/TelecomSudParis/TravauxRecherche/Web/React/complexnet/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/cjs/src/connection.js:790:26)
    at handle (/Users/vgauthier/Documents/TelecomSudParis/TravauxRecherche/Web/React/complexnet/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/cjs/src/connection.js:476:6)
    at TLSSocket.data (/Users/vgauthier/Documents/TelecomSudParis/TravauxRecherche/Web/React/complexnet/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/cjs/src/connection.js:315:9)
    at TLSSocket.emit (node:events:518:28)
    at TLSSocket.emit (node:domain:488:12)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '42704',
  position: '51',
  file: 'parse_type.c',
  line: '270',
  routine: 'typenameType'
}

 pnpm run db:migrate

> complexnet@0.5 db:migrate /Users/vgauthier/Documents/TelecomSudParis/TravauxRecherche/Web/React/complexnet
> tsx src/db/migrate.ts

PostgresError: type "VECTOR(3)" does not exist
    at ErrorResponse (/Users/vgauthier/Documents/TelecomSudParis/TravauxRecherche/Web/React/complexnet/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/cjs/src/connection.js:790:26)
    at handle (/Users/vgauthier/Documents/TelecomSudParis/TravauxRecherche/Web/React/complexnet/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/cjs/src/connection.js:476:6)
    at TLSSocket.data (/Users/vgauthier/Documents/TelecomSudParis/TravauxRecherche/Web/React/complexnet/node_modules/.pnpm/postgres@3.4.3/node_modules/postgres/cjs/src/connection.js:315:9)
    at TLSSocket.emit (node:events:518:28)
    at TLSSocket.emit (node:domain:488:12)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:390:5)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:190:23) {
  severity_local: 'ERROR',
  severity: 'ERROR',
  code: '42704',
  position: '51',
  file: 'parse_type.c',
  line: '270',
  routine: 'typenameType'
}

Expected behavior

ALTER TABLE "publications" ADD COLUMN "embedding" vector(512);

Environment & setup

using pgvector-node https://github.com/pgvector/pgvector-node

jackkweyunga commented 1 month ago

I had to manually edit the file before migrating. Same happens with the push command. @vgauthier how did you proceed ?

vgauthier commented 1 month ago

@jackkweyunga same as you, but I am not sure if the bug come from package Drizzle or pgvector-node package