Skip to content

Commit

Permalink
fix: Disable foreign keys check for purge (#281)
Browse files Browse the repository at this point in the history
Co-authored-by: Gassan Gousseinov <[email protected]>
  • Loading branch information
theofidry and gassan authored Nov 13, 2024
1 parent 821a4bb commit 38daaf7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Bridge/Doctrine/Purger/Purger.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Doctrine\Common\DataFixtures\Purger\ORMPurger as DoctrineOrmPurger;
use Doctrine\Common\DataFixtures\Purger\PHPCRPurger as DoctrinePhpCrPurger;
use Doctrine\Common\DataFixtures\Purger\PurgerInterface as DoctrinePurgerInterface;
use Doctrine\DBAL\Platforms\MariaDBPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\ODM\MongoDB\DocumentManager as DoctrineMongoDocumentManager;
use Doctrine\ODM\PHPCR\DocumentManager as DoctrinePhpCrDocumentManager;
Expand Down Expand Up @@ -93,7 +94,7 @@ public function purge(): void
$disableFkChecks = (
$this->purger instanceof DoctrineOrmPurger
&& in_array($this->purgeMode->getValue(), [PurgeMode::createDeleteMode()->getValue(), PurgeMode::createTruncateMode()->getValue()])
&& $this->purger->getObjectManager()->getConnection()->getDatabasePlatform() instanceof MySqlPlatform
&& $this->doesDatabaseSupportTruncate()
);

if ($disableFkChecks) {
Expand Down Expand Up @@ -136,4 +137,12 @@ private static function createPurger(ObjectManager $manager, ?PurgeMode $purgeMo
)
);
}

private function doesDatabaseSupportTruncate(): bool
{
$platform = $this->purger->getObjectManager()->getConnection()->getDatabasePlatform();

return $platform instanceof MySqlPlatform
|| $platform instanceof MariaDBPlatform;
}
}

0 comments on commit 38daaf7

Please sign in to comment.