mirror of
https://github.com/nextcloud/server.git
synced 2026-02-19 02:38:40 -05:00
fix: Add options to support all used features by core
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
f73f14207c
commit
00d483585b
2 changed files with 40 additions and 5 deletions
|
|
@ -91,7 +91,23 @@ class AddMissingIndices extends Command {
|
|||
$table = $schema->getTable($missingIndex['tableName']);
|
||||
if (!$table->hasIndex($missingIndex['indexName'])) {
|
||||
$output->writeln('<info>Adding additional ' . $missingIndex['indexName'] . ' index to the ' . $table->getName() . ' table, this can take some time...</info>');
|
||||
$table->addIndex($missingIndex['columns'], $missingIndex['indexName']);
|
||||
|
||||
if ($missingIndex['dropUnnamedIndex']) {
|
||||
foreach ($table->getIndexes() as $index) {
|
||||
$columns = $index->getColumns();
|
||||
if ($columns === $missingIndex['columns']) {
|
||||
$table->dropIndex($index->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($missingIndex['uniqueIndex']) {
|
||||
$table->addUniqueIndex($missingIndex['columns'], $missingIndex['indexName'], $missingIndex['options']);
|
||||
} else {
|
||||
$table->addIndex($missingIndex['columns'], $missingIndex['indexName'], [], $missingIndex['options']);
|
||||
}
|
||||
|
||||
|
||||
$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
|
||||
if ($dryRun && $sqlQueries !== null) {
|
||||
$output->writeln($sqlQueries);
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
|
||||
* @copyright Copyright (c) 2023 Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
* @author Julius Härtl <jus@bitgrid.net>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
|
|
@ -34,24 +36,41 @@ namespace OCP\DB\Events;
|
|||
* @since 28.0.0
|
||||
*/
|
||||
class AddMissingIndicesEvent extends \OCP\EventDispatcher\Event {
|
||||
/** @var array<array-key, array{tableName: string, indexName: string, columns: string[]}> */
|
||||
/** @var array<array-key, array{tableName: string, indexName: string, columns: string[], options: array{}, dropUnnamedIndex: bool, uniqueIndex: bool}> */
|
||||
private array $missingIndices = [];
|
||||
|
||||
/**
|
||||
* @param string[] $columns
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function addMissingIndex(string $tableName, string $indexName, array $columns): void {
|
||||
public function addMissingIndex(string $tableName, string $indexName, array $columns, array $options = [], bool $dropUnnamedIndex = false): void {
|
||||
$this->missingIndices[] = [
|
||||
'tableName' => $tableName,
|
||||
'indexName' => $indexName,
|
||||
'columns' => $columns
|
||||
'columns' => $columns,
|
||||
'options' => $options,
|
||||
'dropUnnamedIndex' => $dropUnnamedIndex,
|
||||
'uniqueIndex' => false,
|
||||
];
|
||||
}
|
||||
/**
|
||||
* @param string[] $columns
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function addMissingUniqueIndex(string $tableName, string $indexName, array $columns, array $options = [], bool $dropUnnamedIndex = false): void {
|
||||
$this->missingIndices[] = [
|
||||
'tableName' => $tableName,
|
||||
'indexName' => $indexName,
|
||||
'columns' => $columns,
|
||||
'options' => $options,
|
||||
'dropUnnamedIndex' => $dropUnnamedIndex,
|
||||
'uniqueIndex' => true,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 28.0.0
|
||||
* @return array<array-key, array{tableName: string, indexName: string, columns: string[]}>
|
||||
* @return array<array-key, array{tableName: string, indexName: string, columns: string[], options: array{}, dropUnnamedIndex: bool, uniqueIndex: bool}>
|
||||
*/
|
||||
public function getMissingIndices(): array {
|
||||
return $this->missingIndices;
|
||||
|
|
|
|||
Loading…
Reference in a new issue