FIX convert index definitions to reflect actual support

It is not uncommon for an index to be defined as e.g. 'fulltext'
which SQLite3 does not support without a module to create a
virtual table (rather than an index on an existing one). The code
already in place sees that definitions be updated to 'index' on
the fly during creation and later inspection (indexList) - which
causes issue when comparing existing table definitions to what
SilverStripe expects by DataObject configuration. This discrepency
leads to tables constantly being marked to update, although
effectively nothing actually changes. We can save these CPU cycles
and a bit of head scratching by converting to a supported index type.
This commit is contained in:
NightjarNZ 2018-10-16 21:57:51 +13:00
parent 0fa6b0fde7
commit 5eacbe7842
2 changed files with 12 additions and 3 deletions

View File

@ -491,7 +491,7 @@ class SQLite3Database extends Database
/**
* Fetch the name of the most recent savepoint
*
*
* @return string
*/
protected function getTransactionSavepointName()

View File

@ -286,7 +286,7 @@ class SQLite3SchemaManager extends DBSchemaManager
// Then alter the table column
$database = $this->database;
$database->withTransaction(function() use ($database, $queries, $indexList) {
$database->withTransaction(function () use ($database, $queries, $indexList) {
foreach ($queries as $query) {
$database->query($query . ';');
}
@ -330,7 +330,7 @@ class SQLite3SchemaManager extends DBSchemaManager
// Then alter the table column
$database = $this->database;
$database->withTransaction(function() use ($database, $queries) {
$database->withTransaction(function () use ($database, $queries) {
foreach ($queries as $query) {
$database->query($query . ';');
}
@ -431,6 +431,15 @@ class SQLite3SchemaManager extends DBSchemaManager
return $this->buildSQLiteIndexName($table, $index);
}
protected function convertIndexSpec($indexSpec)
{
$supportedIndexTypes = ['index', 'unique'];
if (isset($indexSpec['type']) && !in_array($indexSpec['type'], $supportedIndexTypes)) {
$indexSpec['type'] = 'index';
}
return parent::convertIndexSpec($indexSpec);
}
public function indexList($table)
{
$indexList = array();