Skip to content

Commit

Permalink
[postgres] initialize sequences (auto-increment) on tables
Browse files Browse the repository at this point in the history
  • Loading branch information
stephpy committed Feb 18, 2016
1 parent b64dafd commit ee6c0a8
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 ee6c0a8

Please sign in to comment.