Skip to content

Commit 9131e30

Browse files
committed
use Table::addPrimaryKeyConstraint() with Doctrine DBAL 4.3+
1 parent 7d4d3f1 commit 9131e30

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Adapter/DoctrineDbalAdapter.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
use Doctrine\DBAL\Exception\TableNotFoundException;
2020
use Doctrine\DBAL\ParameterType;
2121
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
22+
use Doctrine\DBAL\Schema\Name\Identifier;
23+
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
24+
use Doctrine\DBAL\Schema\PrimaryKeyConstraint;
2225
use Doctrine\DBAL\Schema\Schema;
2326
use Doctrine\DBAL\Tools\DsnParser;
2427
use Symfony\Component\Cache\Exception\InvalidArgumentException;
@@ -378,6 +381,11 @@ private function addTableToSchema(Schema $schema): void
378381
$table->addColumn($this->dataCol, 'blob', ['length' => 16777215]);
379382
$table->addColumn($this->lifetimeCol, 'integer', ['unsigned' => true, 'notnull' => false]);
380383
$table->addColumn($this->timeCol, 'integer', ['unsigned' => true]);
381-
$table->setPrimaryKey([$this->idCol]);
384+
385+
if (class_exists(PrimaryKeyConstraint::class)) {
386+
$table->addPrimaryKeyConstraint(new PrimaryKeyConstraint(null, [new UnqualifiedName(Identifier::unquoted($this->idCol))], true));
387+
} else {
388+
$table->setPrimaryKey([$this->idCol]);
389+
}
382390
}
383391
}

0 commit comments

Comments
 (0)