Skip to content

PHPLARA-256 Add Schema::ensureVectorExtensionExists() to check Atlas Search availability - #3558

Draft
GromNaN wants to merge 1 commit into
mongodb:5.xfrom
GromNaN:phplara-256-ensure-vector-extension-exists
Draft

PHPLARA-256 Add Schema::ensureVectorExtensionExists() to check Atlas Search availability#3558
GromNaN wants to merge 1 commit into
mongodb:5.xfrom
GromNaN:phplara-256-ensure-vector-extension-exists

Conversation

@GromNaN

@GromNaN GromNaN commented Jul 29, 2026

Copy link
Copy Markdown
Member

PHPLARA-256

Laravel 12.51 added Schema::ensureVectorExtensionExists() to verify that the vector extension is installed before creating vector columns and indexes. On PostgreSQL it creates the pgvector extension; on other connections the base implementation throws "Extensions are only supported by Postgres".

On MongoDB, the equivalent requirement for Blueprint::vectorSearchIndex() is Atlas Search. The method now lists the search indexes of a collection, which does not need to exist, and converts the "not supported" server error into an explicit RuntimeException:

// Throws unless the deployment supports Atlas Search
Schema::ensureVectorExtensionExists();

Schema::create('books', function (Blueprint $collection) {
    $collection->vectorSearchIndex([
        'fields' => [['type' => 'vector', 'path' => 'embedding', 'numDimensions' => 1536, 'similarity' => 'cosine']],
    ], 'vector');
});

MongoDB\Exception\SearchNotSupportedException is caught when the installed version of mongodb/mongodb throws it, with a fallback on the error codes for older versions.

…Search availability

Laravel uses this method to verify the vector extension is installed before
creating vector indexes. On MongoDB, vector search indexes require Atlas Search,
which is detected by listing the search indexes of a collection.
@GromNaN
GromNaN requested a review from a team as a code owner July 29, 2026 10:08
@GromNaN
GromNaN requested review from Copilot and paulinevos July 29, 2026 10:08
Comment thread src/Schema/Builder.php
try {
// The collection doesn't need to exist to know whether Atlas Search is available
$collection->listSearchIndexes(['name' => 'any']);
} catch (SearchNotSupportedException $exception) {
Comment thread src/Schema/Builder.php
// The collection doesn't need to exist to know whether Atlas Search is available
$collection->listSearchIndexes(['name' => 'any']);
} catch (SearchNotSupportedException $exception) {
throw new RuntimeException($message . $exception->getMessage(), 0, $exception);
Comment thread src/Schema/Builder.php
/** @internal */
public static function isAtlasSearchNotSupportedException(ServerException $e): bool
{
if ($e instanceof SearchNotSupportedException) {

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds MongoDB support for Laravel’s Schema::ensureVectorExtensionExists() by treating Atlas Search availability as the “vector extension” prerequisite for creating/searching vector and search indexes.

Changes:

  • Implement MongoDB\Laravel\Schema\Builder::ensureVectorExtensionExists() to detect Atlas Search support via listSearchIndexes() and throw a RuntimeException when unsupported.
  • Update test infrastructure to skip/target Atlas Search–dependent tests based on server capability, and add coverage for ensureVectorExtensionExists().
  • Update the schema skill reference to document the new “fail early” workflow.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
src/Schema/Builder.php Adds ensureVectorExtensionExists() and extends Atlas Search capability detection logic.
tests/TestCase.php Refactors Atlas Search capability checks into reusable helpers for conditional skipping.
tests/SchemaTest.php Adds tests for Schema::ensureVectorExtensionExists() for both supported/unsupported deployments.
resources/boost/skills/laravel-mongodb/references/schema.md Documents calling Schema::ensureVectorExtensionExists() before creating search/vector search indexes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Schema/Builder.php
Comment on lines +401 to +412
$message = 'Atlas Search is not available on this MongoDB deployment. Use MongoDB Atlas or a local Atlas deployment. ';

try {
// The collection doesn't need to exist to know whether Atlas Search is available
$collection->listSearchIndexes(['name' => 'any']);
} catch (SearchNotSupportedException $exception) {
throw new RuntimeException($message . $exception->getMessage(), 0, $exception);
} catch (ServerException $exception) {
// mongodb/mongodb 1.x doesn't throw SearchNotSupportedException
if (self::isAtlasSearchNotSupportedException($exception)) {
throw new RuntimeException($message . $exception->getMessage(), 0, $exception);
}
Comment thread tests/SchemaTest.php
Comment on lines +710 to +712
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Atlas Search is not available on this MongoDB deployment.');

@GromNaN GromNaN left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mark this PR as "draft", waiting for PHPLARA-255.

Comment thread src/Schema/Builder.php

try {
// The collection doesn't need to exist to know whether Atlas Search is available
$collection->listSearchIndexes(['name' => 'any']);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can bump the minimum version of the lib to 2.2, so this exception is always thrown. And not try to catch the exception.

This would be done with PHPLARA-255.

@GromNaN
GromNaN marked this pull request as draft July 30, 2026 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants