Compare commits
2 Commits
a99bbf92e1
...
252d398174
Author | SHA1 | Date | |
---|---|---|---|
252d398174 | |||
ee10268784 |
@ -66,4 +66,49 @@ class DatabaseUtility
|
||||
return GeneralUtility::makeInstance(ConnectionPool::class)
|
||||
->getConnectionForTable($tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* testAndCreateIndex
|
||||
*/
|
||||
public static function testAndCreateIndex(
|
||||
$table, $indexName, $indexColumns, $type
|
||||
) {
|
||||
$connection = GeneralUtility::makeInstance(
|
||||
ConnectionPool::class
|
||||
)->getConnectionForTable($table);
|
||||
$existTestQuery = "
|
||||
SHOW TABLES LIKE '${table}'
|
||||
";
|
||||
$existTestResult = $connection
|
||||
->executeQuery($existTestQuery)
|
||||
->fetchAll();
|
||||
if (!count($existTestResult)) {
|
||||
return;
|
||||
}
|
||||
$indexTestQuery = "
|
||||
SHOW INDEX FROM ${table}
|
||||
WHERE Key_name = '${indexName}'
|
||||
";
|
||||
$indexTestResult = $connection
|
||||
->executeQuery($indexTestQuery)
|
||||
->fetchAll();
|
||||
if (count($indexTestResult)) {
|
||||
return;
|
||||
}
|
||||
switch ($type) {
|
||||
case 'btree':
|
||||
$queryCreate = "
|
||||
CREATE INDEX ${indexName}
|
||||
USING BTREE ON ${table} (${indexColumns})
|
||||
";
|
||||
break;
|
||||
case 'fulltext':
|
||||
$queryCreate = "
|
||||
CREATE FULLTEXT INDEX ${indexName}
|
||||
ON ${table} (${indexColumns})
|
||||
";
|
||||
break;
|
||||
}
|
||||
$connection->executeQuery($queryCreate);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user