-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathCreateIndices.php
More file actions
53 lines (42 loc) · 1.54 KB
/
CreateIndices.php
File metadata and controls
53 lines (42 loc) · 1.54 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
<?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\Share;
use OCA\Polls\Db\V7\IndexManager;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
class CreateIndices implements IRepairStep {
public function __construct(
private IndexManager $indexManager,
private IDBConnection $connection,
private Schema $schema,
) {
}
public function getName() {
return 'Polls - Create all unique and optional indices and foreign key constraints';
}
public function run(IOutput $output): void {
$messages = [];
// secure, that the schema is updated to the current status
$this->schema = $this->connection->createSchema();
$this->indexManager->setSchema($this->schema);
// remove foreign keys from the share table
// cannot be used anymore since v8.0.0
$messages = array_merge($messages, $this->indexManager->removeForeignKeysFromTable(Share::TABLE));
$messages = array_merge($messages, $this->indexManager->createForeignKeyConstraints());
$messages = array_merge($messages, $this->indexManager->createUniqueIndices());
$messages = array_merge($messages, $this->indexManager->createOptionalIndices());
$this->connection->migrateToSchema($this->schema);
foreach ($messages as $message) {
$output->info($message);
}
$output->info('Polls - Foreign key contraints created.');
$output->info('Polls - Indices created.');
}
}