Skip to content

Commit 0436a01

Browse files
committed
use Table::addPrimaryKeyConstraint() with Doctrine DBAL 4.3+
1 parent e1dae80 commit 0436a01

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Store/DoctrineDbalStore.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
use Doctrine\DBAL\Exception\TableNotFoundException;
1919
use Doctrine\DBAL\ParameterType;
2020
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
21+
use Doctrine\DBAL\Schema\Name\Identifier;
22+
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
23+
use Doctrine\DBAL\Schema\PrimaryKeyConstraint;
2124
use Doctrine\DBAL\Schema\Schema;
2225
use Doctrine\DBAL\Tools\DsnParser;
2326
use Symfony\Component\Lock\Exception\InvalidArgumentException;
@@ -214,7 +217,12 @@ public function configureSchema(Schema $schema, \Closure $isSameDatabase): void
214217
$table->addColumn($this->idCol, 'string', ['length' => 64]);
215218
$table->addColumn($this->tokenCol, 'string', ['length' => 44]);
216219
$table->addColumn($this->expirationCol, 'integer', ['unsigned' => true]);
217-
$table->setPrimaryKey([$this->idCol]);
220+
221+
if (class_exists(PrimaryKeyConstraint::class)) {
222+
$table->addPrimaryKeyConstraint(new PrimaryKeyConstraint(null, [new UnqualifiedName(Identifier::unquoted($this->idCol))], true));
223+
} else {
224+
$table->setPrimaryKey([$this->idCol]);
225+
}
218226
}
219227

220228
/**

0 commit comments

Comments
 (0)