Reset autoincrements on SQLite with our ResetAutoIncrementPurger too and make it default for fixtures load

This commit is contained in:
Jan Böhmer 2023-06-18 22:06:06 +02:00
parent fe1715259a
commit 4977f6c270
3 changed files with 20 additions and 4 deletions

View file

@ -27,6 +27,7 @@ use Doctrine\Common\DataFixtures\Purger\PurgerInterface;
use Doctrine\Common\DataFixtures\Sorter\TopologicalSorter;
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\Identifier;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\ClassMetadata;
@ -188,7 +189,7 @@ class ResetAutoIncrementORMPurger implements PurgerInterface, ORMPurgerInterface
}
//Reseting autoincrement is only supported on MySQL platforms
if ($platform instanceof AbstractMySQLPlatform) {
if ($platform instanceof AbstractMySQLPlatform || $platform instanceof SqlitePlatform) {
$connection->beginTransaction();
$connection->executeQuery($this->getResetAutoIncrementSQL($tbl, $platform));
}
@ -204,7 +205,13 @@ class ResetAutoIncrementORMPurger implements PurgerInterface, ORMPurgerInterface
{
$tableIdentifier = new Identifier($tableName);
return 'ALTER TABLE '. $tableIdentifier->getQuotedName($platform) .' AUTO_INCREMENT = 1;';
if ($platform instanceof AbstractMySQLPlatform) {
return 'ALTER TABLE '.$tableIdentifier->getQuotedName($platform).' AUTO_INCREMENT = 1;';
}
if ($platform instanceof SqlitePlatform) {
return 'DELETE FROM `sqlite_sequence` WHERE name = \''.$tableIdentifier->getQuotedName($platform).'\';';
}
}
/**