{"record":{"id":"f711cb714cf9bf3a","repo":"laravel/framework","slug":"extensions-are-only-supported-by-postgres","errorCode":null,"errorMessage":"Extensions are only supported by Postgres.","messagePattern":"Extensions are only supported by Postgres\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Schema/Builder.php","lineNumber":683,"sourceCode":"     */\n    public function ensureVectorExtensionExists($schema = null)\n    {\n        $this->ensureExtensionExists('vector', $schema);\n    }\n\n    /**\n     * Create a new extension on the schema if it does not exist.\n     *\n     * @param  string  $name\n     * @param  string|null  $schema\n     * @return void\n     *\n     * @throws \\RuntimeException\n     */\n    public function ensureExtensionExists($name, $schema = null)\n    {\n        if (! $this->getConnection() instanceof PostgresConnection) {\n            throw new RuntimeException('Extensions are only supported by Postgres.');\n        }\n\n        $name = $this->getConnection()->getSchemaGrammar()->wrap($name);\n\n        $this->getConnection()->statement(match (filled($schema)) {\n            true => \"create extension if not exists {$name} schema {$this->getConnection()->getSchemaGrammar()->wrap($schema)}\",\n            false => \"create extension if not exists {$name}\",\n        });\n    }\n\n    /**\n     * Execute the blueprint to build / modify the table.\n     *\n     * @param  \\Illuminate\\Database\\Schema\\Blueprint  $blueprint\n     * @return void\n     */\n    protected function build(Blueprint $blueprint)\n    {","sourceCodeStart":665,"sourceCodeEnd":701,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Schema/Builder.php#L665-L701","documentation":"Builder::ensureExtensionExists() hard-checks that the connection is a PostgresConnection and throws RuntimeException otherwise, because CREATE EXTENSION is a Postgres-only DDL. ensureVectorExtensionExists() delegates here, so it inherits the same restriction. The guard is an explicit instanceof - no fallback, no no-op.","triggerScenarios":"Calling Schema::ensureExtensionExists($name, $schema) or Schema::ensureVectorExtensionExists($schema) on any non-Postgres connection (mysql, sqlite, sqlsrv, or a custom driver whose Connection class is not Illuminate\\Database\\PostgresConnection).","commonSituations":"A migration that unconditionally calls ensureVectorExtensionExists() but is run against the testing suite's SQLite connection; an app migrated from Postgres to MySQL where the extension bootstrap was left in place; a multi-database app that runs the same migration set on every connection.","solutions":["Gate the call on the connection driver: if (Schema::getConnection() instanceof \\Illuminate\\Database\\PostgresConnection).","Move ensureExtensionExists / ensureVectorExtensionExists calls into a Postgres-only migration or a service provider branch keyed on config('database.default').","In tests, skip these migrations on SQLite or stub them out via a testing-specific migration path."],"exampleFix":"// before\nSchema::ensureVectorExtensionExists();\n\n// after\nuse Illuminate\\Database\\PostgresConnection;\n\nif (Schema::getConnection() instanceof PostgresConnection) {\n    Schema::ensureVectorExtensionExists();\n}","handlingStrategy":"type-guard","validationCode":"use Illuminate\\Database\\PostgresConnection;\n\n$connection = Schema::getConnection();\nif ($connection instanceof PostgresConnection) {\n    Schema::ensureVectorExtensionExists();\n} else {\n    throw new \\DomainException('Vector extensions require a Postgres connection.');\n}","typeGuard":"use Illuminate\\Database\\PostgresConnection;\n\nfunction isPostgres(\\Illuminate\\Database\\Connection $connection): bool\n{\n    return $connection instanceof PostgresConnection;\n}","tryCatchPattern":"try {\n    Schema::ensureExtensionExists('vector');\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'only supported by Postgres')) {\n        return; // skip on non-Postgres connections\n    }\n    throw $e;\n}","preventionTips":["Centralise extension setup in a Postgres-only service provider or migration.","Make the testing connection Postgres-compatible or skip extension migrations in test env.","Guard any code path inherited from a Postgres codebase when porting to a new engine."],"tags":["schema","database-driver","postgres","extensions","runtime-exception"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}