diff --git a/src/Platforms/AbstractMySQLPlatform.php b/src/Platforms/AbstractMySQLPlatform.php index d4c72361c2..f290136182 100644 --- a/src/Platforms/AbstractMySQLPlatform.php +++ b/src/Platforms/AbstractMySQLPlatform.php @@ -801,6 +801,7 @@ protected function initializeDoctrineTypeMappings(): void 'tinytext' => Types::TEXT, 'varbinary' => Types::BINARY, 'varchar' => Types::STRING, + 'vector' => Types::VECTOR, 'year' => Types::DATE_MUTABLE, ]; } diff --git a/src/Platforms/MariaDBPlatform.php b/src/Platforms/MariaDBPlatform.php index 585cfaf2e7..320d900b77 100644 --- a/src/Platforms/MariaDBPlatform.php +++ b/src/Platforms/MariaDBPlatform.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Platforms\Keywords\KeywordList; use Doctrine\DBAL\Platforms\Keywords\MariaDBKeywords; use Doctrine\DBAL\Schema\ForeignKeyConstraint; +use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\TableDiff; use Doctrine\DBAL\Types\JsonType; use Doctrine\Deprecations\Deprecation; @@ -179,4 +180,13 @@ public function getVectorTypeDeclarationSQL(array $column): string { return AbstractPlatform::getVectorTypeDeclarationSQL($column); } + + protected function getCreateIndexSQLFlags(Index $index): string + { + if ($index->getType() === Index\IndexType::VECTOR) { + return 'VECTOR '; + } + + return parent::getCreateIndexSQLFlags($index); + } } diff --git a/src/Schema/Index.php b/src/Schema/Index.php index 777348fab9..9792ba3565 100644 --- a/src/Schema/Index.php +++ b/src/Schema/Index.php @@ -627,6 +627,11 @@ private function inferType(): ?IndexType $matches[] = 'spatial'; } + if ($this->hasFlag('vector')) { + $type = IndexType::VECTOR; + $matches[] = 'vector'; + } + if (count($matches) > 1) { Deprecation::trigger( 'doctrine/dbal', diff --git a/src/Schema/Index/IndexType.php b/src/Schema/Index/IndexType.php index 646668853f..560e8c334d 100644 --- a/src/Schema/Index/IndexType.php +++ b/src/Schema/Index/IndexType.php @@ -10,4 +10,5 @@ enum IndexType case UNIQUE; case FULLTEXT; case SPATIAL; + case VECTOR; } diff --git a/src/Schema/IndexEditor.php b/src/Schema/IndexEditor.php index ec06f0743a..af998d0f10 100644 --- a/src/Schema/IndexEditor.php +++ b/src/Schema/IndexEditor.php @@ -156,6 +156,8 @@ public function create(): Index $flags[] = 'fulltext'; } elseif ($this->type === IndexType::SPATIAL) { $flags[] = 'spatial'; + } elseif ($this->type === IndexType::VECTOR) { + $flags[] = 'vector'; } if ($this->isClustered) { diff --git a/src/Schema/MySQLSchemaManager.php b/src/Schema/MySQLSchemaManager.php index e581926faf..006f30cc78 100644 --- a/src/Schema/MySQLSchemaManager.php +++ b/src/Schema/MySQLSchemaManager.php @@ -173,6 +173,13 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column $scale = (int) $tableColumn['numeric_scale']; } + break; + + case 'vector': + if (preg_match('/^vector\((\d+)\)$/', $tableColumn['column_type'], $matches) !== false) { + $length = (int) $matches[1]; + } + break; } diff --git a/tests/Functional/Schema/MySQLSchemaManagerTest.php b/tests/Functional/Schema/MySQLSchemaManagerTest.php index eb5dad7fc8..fd6b5531fd 100644 --- a/tests/Functional/Schema/MySQLSchemaManagerTest.php +++ b/tests/Functional/Schema/MySQLSchemaManagerTest.php @@ -9,7 +9,9 @@ use Doctrine\DBAL\Exception\DatabaseRequired; use Doctrine\DBAL\Platforms\AbstractMySQLPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\MariaDB110700Platform; use Doctrine\DBAL\Platforms\MariaDBPlatform; +use Doctrine\DBAL\Platforms\MySQL90Platform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnEditor; use Doctrine\DBAL\Schema\Index; @@ -799,7 +801,15 @@ public function testColumnIntrospection(): void $tableEditor = Table::editor() ->setUnquotedName('test_column_introspection'); - $doctrineTypes = array_keys(Type::getTypesMap()); + $types = Type::getTypesMap(); + + $platform = $this->connection->getDatabasePlatform(); + + if (! $platform instanceof MySQL90Platform && ! $platform instanceof MariaDB110700Platform) { + unset($types[Types::VECTOR]); + } + + $doctrineTypes = array_keys($types); foreach ($doctrineTypes as $type) { $columnEditor = Column::editor() diff --git a/tests/Platforms/MariaDBPlatformTest.php b/tests/Platforms/MariaDBPlatformTest.php index 51b2e5880c..5b6dfb6701 100644 --- a/tests/Platforms/MariaDBPlatformTest.php +++ b/tests/Platforms/MariaDBPlatformTest.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\Exception\NotSupported; use Doctrine\DBAL\Platforms\MariaDBPlatform; +use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Types\Types; class MariaDBPlatformTest extends AbstractMySQLPlatformTestCase @@ -43,4 +44,16 @@ public function testGetVectorTypeDeclarationSQL(): void self::expectException(NotSupported::class); $this->platform->getVectorTypeDeclarationSQL(['length' => 2048]); } + + public function testGeneratesVectorIndexCreationSql(): void + { + $indexDef = Index::editor() + ->setUnquotedColumnNames('test') + ->setUnquotedName('idx_test') + ->setType(Index\IndexType::VECTOR) + ->create(); + + $sql = $this->platform->getCreateIndexSQL($indexDef, 'test_table'); + self::assertEquals('CREATE VECTOR INDEX idx_test ON test_table (test)', $sql); + } }