mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge branch '5.2' into 5
This commit is contained in:
commit
c27f66bd48
@ -569,23 +569,21 @@ class MySQLDatabase extends Database implements TransactionManager
|
|||||||
// Not simply using "TRUNCATE TABLE \"$table\"" because DELETE is a lot quicker
|
// Not simply using "TRUNCATE TABLE \"$table\"" because DELETE is a lot quicker
|
||||||
// than TRUNCATE which is very relevant during unit testing. Using TRUNCATE will lead to an
|
// than TRUNCATE which is very relevant during unit testing. Using TRUNCATE will lead to an
|
||||||
// approximately 50% increase it the total time of running unit tests.
|
// approximately 50% increase it the total time of running unit tests.
|
||||||
//
|
$this->query("DELETE FROM \"$table\"");
|
||||||
// Using max(ID) to determine if the table should reset its auto-increment, rather than using
|
|
||||||
// SELECT "AUTO_INCREMENT" FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?
|
// Check if resetting the auto-increment is needed
|
||||||
// after deleting from the table, because in MySQL 8, under certain conditions, notably
|
|
||||||
// when running behat, sometimes the auto-increment was being reset to 2 for unknown reasons
|
// First run ANALYZE TABLE to reset table stats which are cached for 24 hours by
|
||||||
$self = $this;
|
// default in MySQL 8
|
||||||
$fn = function () use ($self, $table) {
|
$this->query("ANALYZE TABLE \"$table\"");
|
||||||
$maxID = $self->query("SELECT MAX(ID) FROM \"$table\"")->value();
|
|
||||||
$self->query("DELETE FROM \"$table\"");
|
$autoIncrement = $this->preparedQuery(
|
||||||
if ($maxID > 0) {
|
'SELECT "AUTO_INCREMENT" FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?',
|
||||||
$self->query("ALTER TABLE \"$table\" AUTO_INCREMENT = 1");
|
[ $this->getSelectedDatabase(), $table]
|
||||||
}
|
)->value();
|
||||||
};
|
|
||||||
if ($this->supportsTransactions()) {
|
if ($autoIncrement > 1) {
|
||||||
$this->withTransaction($fn);
|
$this->query("ALTER TABLE \"$table\" AUTO_INCREMENT = 1");
|
||||||
} else {
|
|
||||||
$fn();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user