Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Classes/Core/Testbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,8 @@ public function initializeTestDatabaseAndTruncateTables(string $dbPathSqlite = '
$platform = $connection->getDatabasePlatform();
if ($platform instanceof DoctrineMariaDBPlatform || $platform instanceof DoctrineMySQLPlatform) {
$this->truncateAllTablesForMysql();
} elseif ($platform instanceof DoctrinePostgreSQLPlatform) {
$this->truncateAllTablesForPostgres();
} else {
$this->truncateAllTablesForOtherDatabases();
}
Expand Down Expand Up @@ -882,6 +884,24 @@ private function truncateAllTablesForMysql(): void
}
}

/**
* Truncates all PostgreSQL tables and restarts their sequences in one statement.
*/
private function truncateAllTablesForPostgres(): void
{
/** @var Connection $connection */
$connection = GeneralUtility::makeInstance(ConnectionPool::class)
->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
$tableNames = $connection->createSchemaManager()->listTableNames();
if ($tableNames === []) {
return;
}
$quotedTableNames = array_map($connection->quoteIdentifier(...), $tableNames);
$connection->executeStatement(
'TRUNCATE TABLE ' . implode(', ', $quotedTableNames) . ' RESTART IDENTITY CASCADE'
);
}

/**
* Truncates all tables without any database-specific optimizations.
*/
Expand Down