Skip to content

Commit 65985a6

Browse files
committed
fix: Don not rely on possibly incorrect data TABLE_ROWS
For InnoDB tables the value of TABLE_ROWS may be wrong in some situations
1 parent 5690fc2 commit 65985a6

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/Schema/Strategy/MysqlBasedSchemaStrategy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function applySchema(SchemaBuilder $schemaBuilder, Connection $connection
5353
public function deleteData(Connection $connection): void
5454
{
5555
$tablesWithRows = $connection->executeQuery(
56-
'SELECT `TABLE_NAME` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = :table AND `TABLE_ROWS` > 0',
56+
'SELECT `TABLE_NAME` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = :table',
5757
['table' => $connection->getDatabase()],
5858
)->fetchFirstColumn();
5959

tests/Schema/Strategy/MysqlBasedSchemaStrategyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static function () use ($queryLog, $connection) {
206206
$result = [];
207207

208208
// phpcs:ignore Generic.Files.LineLength.TooLong
209-
if ($query === 'SELECT `TABLE_NAME` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = :table AND `TABLE_ROWS` > 0') {
209+
if ($query === 'SELECT `TABLE_NAME` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = :table') {
210210
$result = [['TABLE_NAME' => 'foo']];
211211
}
212212

tests/Schema/Strategy/__snapshots__/mysql_based_schema_strategy_delete_data.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"query": "SELECT `TABLE_NAME` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = :table AND `TABLE_ROWS` > 0",
3+
"query": "SELECT `TABLE_NAME` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = :table",
44
"parameters": {
55
"table": "database_name"
66
},
@@ -19,4 +19,4 @@
1919
{
2020
"statement": "SET foreign_key_checks = 1"
2121
}
22-
]
22+
]

0 commit comments

Comments
 (0)