Skip to content

Commit

Permalink
[TASK] Reset sqlite auto increment sequences if re-using db
Browse files Browse the repository at this point in the history
  • Loading branch information
lolli42 committed Feb 8, 2019
1 parent 36fea7a commit bea53bf
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Classes/Core/Testbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Core\ClassLoadingInformation;
Expand Down Expand Up @@ -795,7 +796,8 @@ public function importXmlDatabaseFixture($path)
*/
public static function resetTableSequences(Connection $connection, string $tableName)
{
if ($connection->getDatabasePlatform() instanceof PostgreSqlPlatform) {
$platform = $connection->getDatabasePlatform();
if ($platform instanceof PostgreSqlPlatform) {
$queryBuilder = $connection->createQueryBuilder();
$queryBuilder->getRestrictions()->removeAll();
$row = $queryBuilder->select('PGT.schemaname', 'S.relname', 'C.attname', 'T.relname AS tablename')
Expand Down Expand Up @@ -827,6 +829,14 @@ public static function resetTableSequences(Connection $connection, string $table
)
);
}
} elseif ($platform instanceof SqlitePlatform) {
// Drop eventually existing sqlite sequence for this table
$connection->exec(
sprintf(
'DELETE FROM sqlite_sequence WHERE name=%s',
$connection->quote($tableName)
)
);
}
}

Expand Down

0 comments on commit bea53bf

Please sign in to comment.