-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathRemoveUniqueIndices.php
More file actions
59 lines (52 loc) · 1.75 KB
/
RemoveUniqueIndices.php
File metadata and controls
59 lines (52 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2021 Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Polls\Command\Db;
use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Command\Command;
use OCA\Polls\Db\V7\IndexManager;
use OCP\IDBConnection;
/**
* @psalm-api
*/
class RemoveUniqueIndices extends Command {
protected string $name = parent::NAME_PREFIX . 'index:remove:unique-indices';
protected string $description = 'Remove all unique indices';
protected array $operationHints = [
'Removes all unique indices.',
'*****************************',
'** Please understand **',
'*****************************',
'This can lead to inconsitent database states, because the uniqueness of data is not guaranteed anymore.',
'Therefore this command is highly NOT RECOMMENDED and should only be executed if you know what you are doing.',
'',
'To recreate the unique indices, run the command \'occ ' . parent::NAME_PREFIX . 'index:create\'',
'Note: NO data migration will be executed, so make sure you have a backup of your database.',
];
public function __construct(
private IndexManager $indexManager,
private IDBConnection $connection,
private Schema $schema,
) {
parent::__construct();
}
protected function runCommands(): int {
// remove constraints and indices
$this->schema = $this->connection->createSchema();
$this->indexManager->setSchema($this->schema);
$this->deleteUniqueIndices();
$this->connection->migrateToSchema($this->schema);
return 0;
}
/**
* remove all unique indices
*/
private function deleteUniqueIndices(): void {
$this->printComment('Remove unique indices');
$messages = $this->indexManager->removeAllUniqueIndices();
$this->printInfo($messages, ' - ');
}
}