Merge pull request #19970 from MoonE/vector-column

Support creating and changing VECTOR column
This commit is contained in:
Maurício Meneghini Fauth 2025-12-05 15:47:47 -03:00 committed by GitHub
commit ca3c713048
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 45 additions and 0 deletions

View File

@ -227,6 +227,19 @@ class Compatibility
return $dbi->isMariaDB() && $dbi->getVersion() >= 100700; // 10.7.0
}
/**
* Check whether the database supports VECTOR data type
*
* @return bool true if VECTOR is supported
*/
public static function isVectorSupported(DatabaseInterface $dbi): bool
{
// @see: https://mariadb.com/docs/release-notes/community-server/old-releases/mariadb-11-7-rolling-releases/mariadb-11-7-1-release-notes#vectors
// @see: https://dev.mysql.com/doc/relnotes/mysql/9.0/en/news-9-0-0.html#mysqld-9-0-0-vectors
return $dbi->isMariaDB() && $dbi->getVersion() >= 110701 || // 11.7.1
$dbi->isMySql() && $dbi->getVersion() >= 90000; // 9.0.0
}
/**
* Returns whether the database server supports virtual columns
*/

View File

@ -776,6 +776,7 @@ class Types
$serverVersion = $this->dbi->getVersion();
$isJsonSupported = Compatibility::isJsonSupported($this->dbi);
$isUUIDSupported = Compatibility::isUUIDSupported($this->dbi);
$isVectorSupported = Compatibility::isVectorSupported($this->dbi);
// most used types
$ret = [
@ -863,6 +864,10 @@ class Types
$ret['UUID'] = ['UUID'];
}
if ($isVectorSupported) {
$ret['VECTOR'] = ['VECTOR'];
}
return $ret;
}

View File

@ -51,6 +51,33 @@ class CompatibilityTest extends TestCase
self::assertSame($expected, Compatibility::isUUIDSupported($dbiStub));
}
/**
* @return array[]
* @psalm-return array<string, array{bool, bool, int}>
*/
public static function providerForTestIsVectorSupported(): array
{
return [
'MySQL 8.99.99' => [false, false, 89999],
'MySQL 9.0.0' => [false, false, 90000],
'MariaDB 11.6.99' => [false, true, 110699],
'MariaDB 11.7.1' => [true, true, 110701],
];
}
/**
* @dataProvider providerForTestIsVectorSupported
*/
public function testIsVectorSupported(bool $expected, bool $isMariaDb, int $version): void
{
$dbiStub = $this->createStub(DatabaseInterface::class);
$dbiStub->method('isMariaDB')->willReturn($isMariaDb);
$dbiStub->method('getVersion')->willReturn($version);
self::assertSame($expected, Compatibility::isVectorSupported($dbiStub));
}
/**
* @return array[]
* @psalm-return array<string, array{bool, bool, int}>