thedevdojo / voyager

Voyager - The Missing Laravel Admin
https://voyager.devdojo.com
MIT License
11.72k stars 2.67k forks source link

Unknown database type vector requested, Doctrine\DBAL\Platforms\PostgreSQL100Platform may not support it. #5759

Closed user3470 closed 1 year ago

user3470 commented 1 year ago

Laravel version

^9.19

PHP version

8.1.2

Voyager version

^1.6

Database

(PostgreSQL) 14.7

Description

I'm using ankane/pgvector but when I try to open "Bread" section in voyager adming I get

Unknown database type vector requested, Doctrine\DBAL\Platforms\PostgreSQL100Platform may not support it.

Steps to reproduce

Install and use ankane/pgvector in a table then try to open Bread

Expected behavior

Open bread

Screenshots

No response

Additional context

Here's is my temporary solutions, hope this helps someone, or future me.

Create a new file VectorType.php in the app/Doctrine/Types folder. If the folder doesn't exist, create it. Add the following code

<?php

namespace App\Doctrine\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;

class VectorType extends Type
{
    const VECTOR = 'vector';

    public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
    {
        return  self::VECTOR;
    }

    public function getName()
    {
        return self::VECTOR;
    }
}

In your config/database.php file, add the following lines to the connections.pgsql array:

'types' => [
    'vector' => App\Doctrine\Types\VectorType::class,
],

Update the boot method in your app/Providers/AppServiceProvider.php file to register the custom type with Doctrine:

use App\Doctrine\Types\VectorType;
use Doctrine\DBAL\Types\Type;
use Illuminate\Support\Facades\Schema;

public function boot()
{
    if (class_exists(Type::class) && !Type::hasType('vector')) {
        Type::addType('vector', VectorType::class);
        $platform = Schema::getConnection()->getDoctrineSchemaManager()->getDatabasePlatform();
        $platform->registerDoctrineTypeMapping('vector', 'vector');
    }
}

Clear your application cache:

php artisan config:cache

Now, try accessing the "Bread" section in Voyager admin.

fletch3555 commented 1 year ago

I don't see this as a Voyager bug. Nothing in your fix is specific to Voyager.

Also, we make a best-effort, but cannot guarantee compatibility with other 3rd-party packages.

In any case, I'm glad you found a solution.

github-actions[bot] commented 8 months ago

This issue has been automatically locked since there has not been any recent activity after it was closed. If you have further questions please ask in our Slack group.