Issues with running prisma migrate when enabling pgvector

theoutlander
HOBBY

2 months ago

I have even upgraded to a paid plan thinking that might have been the issue. In addition I've ran the following commands successfully:

SELECT * FROM pg_available_extensions WHERE name = 'vector';

CREATE EXTENSION IF NOT EXISTS vector;

When I run prisma migrate or prisma db push, I get the following error:

Error: ERROR: extension "pgvector" is not available

DETAIL: Could not open extension control file "/usr/share/postgresql/17/extension/pgvector.control": No such file or directory.

HINT: The extension must first be installed on the system where PostgreSQL is running.

   0: sql_schema_connector::apply_migration::migration_step

           with step=CreateExtension(CreateExtension { id: ExtensionId(0) })

             at schema-engine/connectors/sql-schema-connector/src/apply_migration.rs:28

   1: sql_schema_connector::apply_migration::apply_migration

             at schema-engine/connectors/sql-schema-connector/src/apply_migration.rs:11

   2: schema_core::state::SchemaPush

             at schema-engine/core/src/state.rs:502

I've tried PG 16 and PG 17 templates, but run into the same issue.

My prisma schema starts with

generator client {
  provider        = "prisma-client-js"
  previewFeatures = ["postgresqlExtensions"]
}

datasource db {
  provider   = "postgresql"
  url        = env("DATABASE_URL")
  extensions = [pgvector]
}

// and one of my models has 
embedding         Unsupported("vector")?

I've also tried this by removing the previewFeatures and extensions config so it doesn't try to create pgvector. I get the following error:

Error: P3006

Migration `20250518232917_add_access_token_expiry` failed to apply cleanly to the shadow database. 
Error:
ERROR: extension "pgvector" is not available
DETAIL: Could not open extension control file "/usr/share/postgresql/17/extension/pgvector.control": No such file or directory.
HINT: The extension must first be installed on the system where PostgreSQL is running.
   0: sql_schema_connector::validate_migrations
           with namespaces=None
             at schema-engine/connectors/sql-schema-connector/src/lib.rs:500
   1: schema_core::state::DevDiagnostic
             at schema-engine/core/src/state.rs:281

 ELIFECYCLE  Command failed with exit code 1.

I've also tried running prisma migrate reset and I get the following

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: 20250518232917_add_access_token_expiry

Database error code: 0A000

Database error:
ERROR: extension "pgvector" is not available
DETAIL: Could not open extension control file "/usr/share/postgresql/17/extension/pgvector.control": No such file or directory.
HINT: The extension must first be installed on the system where PostgreSQL is running.

DbError { severity: "ERROR", parsed_severity: Some(Error), code: SqlState(E0A000), message: "extension \"pgvector\" is not available", detail: Some("Could not open extension control file \"/usr/share/postgresql/17/extension/pgvector.control\": No such file or directory."), hint: Some("The extension must first be installed on the system where PostgreSQL is running."), position: None, where_: None, schema: None, table: None, column: None, datatype: None, constraint: None, file: Some("extension.c"), line: Some(542), routine: Some("parse_extension_control_file") }

What is the reason this keeps failing?

Solved$10 Bounty

1 Replies

theoutlander
HOBBY

2 months ago

For anyone else that runs into this, I tried replicating this locally and realized that it was looking for a file called pgvector.control instead of vector.control.

This was caused because of the following command in the migration.sql file:

-- CreateExtension
CREATE EXTENSION IF NOT EXISTS "pgvector";

I changed it to

-- CreateExtension
CREATE EXTENSION IF NOT EXISTS vector;

and it works!!


Status changed to Solved brody about 2 months ago


Status changed to Solved theoutlander about 2 months ago