-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathRemoveIndices.php
More file actions
57 lines (48 loc) · 1.26 KB
/
RemoveIndices.php
File metadata and controls
57 lines (48 loc) · 1.26 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
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2021 Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Polls\Migration\RepairSteps;
use Doctrine\DBAL\Schema\Schema;
use OCA\Polls\Db\V7\IndexManager;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
/**
* Preparation before migration
* Remove all indices and foreign key constraints to avoid errors
* while changing the schema
*
*/
class RemoveIndices implements IRepairStep {
public function __construct(
private IndexManager $indexManager,
private IDBConnection $connection,
private Schema $schema,
) {
}
/*
* @inheritdoc
*/
public function getName() {
return 'Polls - Remove foreign key constraints and generic indices';
}
/*
* @inheritdoc
*/
public function run(IOutput $output): void {
$this->schema = $this->connection->createSchema();
$this->indexManager->setSchema($this->schema);
$messages = $this->indexManager->removeAllForeignKeyConstraints();
foreach ($messages as $message) {
$output->info($message);
}
$messages = $this->indexManager->removeAllUniqueIndices();
foreach ($messages as $message) {
$output->info($message);
}
$this->connection->migrateToSchema($this->schema);
}
}