Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Platforms/AbstractMySQLPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,7 @@ protected function initializeDoctrineTypeMappings(): void
'tinytext' => Types::TEXT,
'varbinary' => Types::BINARY,
'varchar' => Types::STRING,
'vector' => Types::VECTOR,
'year' => Types::DATE_MUTABLE,
];
}
Expand Down
10 changes: 10 additions & 0 deletions src/Platforms/MariaDBPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
5 changes: 5 additions & 0 deletions src/Schema/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions src/Schema/Index/IndexType.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ enum IndexType
case UNIQUE;
case FULLTEXT;
case SPATIAL;
case VECTOR;
}
2 changes: 2 additions & 0 deletions src/Schema/IndexEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions src/Schema/MySQLSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 11 additions & 1 deletion tests/Functional/Schema/MySQLSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
13 changes: 13 additions & 0 deletions tests/Platforms/MariaDBPlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Loading