mirror of
https://github.com/silverstripe/silverstripe-sqlite3
synced 2024-10-22 17:05:37 +02:00
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:
parent
0fa6b0fde7
commit
5eacbe7842
@ -286,7 +286,7 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
|
|
||||||
// Then alter the table column
|
// Then alter the table column
|
||||||
$database = $this->database;
|
$database = $this->database;
|
||||||
$database->withTransaction(function() use ($database, $queries, $indexList) {
|
$database->withTransaction(function () use ($database, $queries, $indexList) {
|
||||||
foreach ($queries as $query) {
|
foreach ($queries as $query) {
|
||||||
$database->query($query . ';');
|
$database->query($query . ';');
|
||||||
}
|
}
|
||||||
@ -330,7 +330,7 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
|
|
||||||
// Then alter the table column
|
// Then alter the table column
|
||||||
$database = $this->database;
|
$database = $this->database;
|
||||||
$database->withTransaction(function() use ($database, $queries) {
|
$database->withTransaction(function () use ($database, $queries) {
|
||||||
foreach ($queries as $query) {
|
foreach ($queries as $query) {
|
||||||
$database->query($query . ';');
|
$database->query($query . ';');
|
||||||
}
|
}
|
||||||
@ -431,6 +431,15 @@ class SQLite3SchemaManager extends DBSchemaManager
|
|||||||
return $this->buildSQLiteIndexName($table, $index);
|
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)
|
public function indexList($table)
|
||||||
{
|
{
|
||||||
$indexList = array();
|
$indexList = array();
|
||||||
|
Loading…
Reference in New Issue
Block a user