I’m working on writing a Prisma extension to support pgvector. All seems fine, and I’ve moved on to writing automated test cases. I’ve been following this methodology for vitest
, which works by attaching to a new, randomly generated schema name for each test suite: DATABASE_URL="postgresql://postgres:postgres@localhost:5432/pgv-test?schema=<random name>"
, and running pnpx prisma migrate deploy
. The problem is, it seems to be having some issue with the Postgres extension on the random schema:
RUN v1.6.0 /Users/cwr/src/prisma-extension-pgvector/package
Error: P3018
A migration failed to apply. New migrations cannot be applied before the error is recovered from. Read more about how to resolve migration issues in a production database: https://pris.ly/d/migrate-resolve
Migration name: 20240614101133_test_init
Database error code: 42704
Database error:
ERROR: type "vector" does not exist
Position:
27 -- CreateTable
28 CREATE TABLE "Vector" (
29 "id" SERIAL NOT NULL,
30 "metadata" JSONB,
31 "testfield" TEXT,
32 "embedding" vector(3),
DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E42704), message: "type "vector" does not exist", detail: None, hint: None, position: Some(Original(755)), where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("parse_type.c"), line: Some(270), routine: Some("typenameType") }
I spent a fair bit of time trying to extend the Prisma migration sql to make sure all schemas had access to the extensions (e.g., trying to apply this, or this by manually adjusting the migration.sql
file) but can’t quite get it to work. This is the native, generated migration.sql
file:
-- CreateExtension
CREATE EXTENSION IF NOT EXISTS "vector";
-- CreateTable
CREATE TABLE "Vector" (
"id" SERIAL NOT NULL,
"metadata" JSONB,
"testfield" TEXT,
"embedding" vector(3),
CONSTRAINT "Vector_pkey" PRIMARY KEY ("id")
);
What magic do I need to add to get it so that vitest
connects to the database at ?schema=foo
, it works?