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
16 changes: 13 additions & 3 deletions Classes/Core/Testbase.php
Original file line number Diff line number Diff line change
Expand Up @@ -874,10 +874,20 @@ private function truncateAllTablesForMysql(): void
while ($tableData = $result->fetchAssociative()) {
$hasChangedAutoIncrement = ((int)$tableData['auto_increment']) > 1;
$hasAtLeastOneRow = (bool)$tableData['has_rows'];
$isChanged = $hasChangedAutoIncrement || $hasAtLeastOneRow;
if ($isChanged) {
$tableName = $tableData['table_name'];
$tableName = $tableData['table_name'];
if ($hasChangedAutoIncrement) {
$connection->truncate($tableName);
} elseif ($hasAtLeastOneRow) {
// MySQL may not expose the current counter for populated auto-increment tables.
// Check the column metadata before using DELETE, which does not reset the counter.
$autoIncrementColumn = $connection->executeQuery(
'SHOW COLUMNS FROM ' . $connection->quoteIdentifier($tableName) . ' WHERE Extra = \'auto_increment\''
)->fetchOne();
if ($autoIncrementColumn === false) {
$connection->executeStatement('DELETE FROM ' . $connection->quoteIdentifier($tableName));
} else {
$connection->truncate($tableName);
}
}
}
}
Expand Down