Skip to content

Commit

Permalink
Merge pull request #41 from stephpy/postgres_behat2
Browse files Browse the repository at this point in the history
[postgres] initialize sequences (auto-increment) on tables
  • Loading branch information
stephpy committed Feb 19, 2016
2 parents b64dafd + ee6c0a8 commit 3c6391e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Rezzza/AliceExtension/Doctrine/ORMPurger.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Internal\CommitOrderCalculator;
use Doctrine\ORM\Mapping\ClassMetadata;
Expand Down Expand Up @@ -111,6 +112,14 @@ private function purgeManager(EntityManager $entityManager)
}
}

if ($platform instanceof PostgreSqlPlatform) {
$sequences = $entityManager->getConnection()->fetchAll("SELECT relname FROM pg_class WHERE relkind='S'");

foreach ($sequences as $sequence) {
$entityManager->getConnection()->exec(sprintf('ALTER SEQUENCE %s RESTART WITH 1', $sequence['relname']));
}
}

// implements hack for Mysql
if ($platform instanceof MySqlPlatform) {
$entityManager->getConnection()->exec('SET foreign_key_checks = 1;');
Expand Down

0 comments on commit 3c6391e

Please sign in to comment.