Skip to content

Commit 371272a

Browse files
committed
use Table::addPrimaryKeyConstraint() with Doctrine DBAL 4.3+
1 parent ee1b504 commit 371272a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Session/Storage/Handler/PdoSessionHandler.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111

1212
namespace Symfony\Component\HttpFoundation\Session\Storage\Handler;
1313

14+
use Doctrine\DBAL\Schema\Name\Identifier;
15+
use Doctrine\DBAL\Schema\Name\UnqualifiedName;
16+
use Doctrine\DBAL\Schema\PrimaryKeyConstraint;
1417
use Doctrine\DBAL\Schema\Schema;
1518
use Doctrine\DBAL\Types\Types;
1619

@@ -224,7 +227,13 @@ public function configureSchema(Schema $schema, ?\Closure $isSameDatabase = null
224227
default:
225228
throw new \DomainException(\sprintf('Creating the session table is currently not implemented for PDO driver "%s".', $this->driver));
226229
}
227-
$table->setPrimaryKey([$this->idCol]);
230+
231+
if (class_exists(PrimaryKeyConstraint::class)) {
232+
$table->addPrimaryKeyConstraint(new PrimaryKeyConstraint(null, [new UnqualifiedName(Identifier::unquoted($this->idCol))], true));
233+
} else {
234+
$table->setPrimaryKey([$this->idCol]);
235+
}
236+
228237
$table->addIndex([$this->lifetimeCol], $this->lifetimeCol.'_idx');
229238
}
230239

0 commit comments

Comments
 (0)