Passed
Push — master ( 7ad038...6c6f41 )
by Morris
13:41 queued 10s
created

Version1011Date20200630192246::changeSchema()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 108
Code Lines 80

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 80
c 1
b 0
f 0
nc 16
nop 3
dl 0
loc 108
rs 8.1252

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * @copyright Copyright (c) 2020 Joas Schilling <[email protected]>
6
 *
7
 * @author Joas Schilling <[email protected]>
8
 *
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
namespace OCA\Files_External\Migration;
27
28
use Closure;
29
use Doctrine\DBAL\Types\Types;
30
use OCP\DB\ISchemaWrapper;
31
use OCP\Migration\IOutput;
32
use OCP\Migration\SimpleMigrationStep;
33
34
class Version1011Date20200630192246 extends SimpleMigrationStep {
35
	/**
36
	 * @param IOutput $output
37
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
38
	 * @param array $options
39
	 * @return null|ISchemaWrapper
40
	 */
41
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
42
		/** @var ISchemaWrapper $schema */
43
		$schema = $schemaClosure();
44
45
		if (!$schema->hasTable('external_mounts')) {
46
			$table = $schema->createTable('external_mounts');
47
			$table->addColumn('mount_id', Types::BIGINT, [
48
				'autoincrement' => true,
49
				'notnull' => true,
50
				'length' => 6,
51
			]);
52
			$table->addColumn('mount_point', Types::STRING, [
53
				'notnull' => true,
54
				'length' => 128,
55
			]);
56
			$table->addColumn('storage_backend', Types::STRING, [
57
				'notnull' => true,
58
				'length' => 64,
59
			]);
60
			$table->addColumn('auth_backend', Types::STRING, [
61
				'notnull' => true,
62
				'length' => 64,
63
			]);
64
			$table->addColumn('priority', Types::INTEGER, [
65
				'notnull' => true,
66
				'length' => 4,
67
				'default' => 100,
68
			]);
69
			$table->addColumn('type', Types::INTEGER, [
70
				'notnull' => true,
71
				'length' => 4,
72
			]);
73
			$table->setPrimaryKey(['mount_id']);
74
		}
75
76
		if (!$schema->hasTable('external_applicable')) {
77
			$table = $schema->createTable('external_applicable');
78
			$table->addColumn('applicable_id', Types::BIGINT, [
79
				'autoincrement' => true,
80
				'notnull' => true,
81
				'length' => 6,
82
			]);
83
			$table->addColumn('mount_id', Types::BIGINT, [
84
				'notnull' => true,
85
				'length' => 6,
86
			]);
87
			$table->addColumn('type', Types::INTEGER, [
88
				'notnull' => true,
89
				'length' => 4,
90
			]);
91
			$table->addColumn('value', Types::STRING, [
92
				'notnull' => false,
93
				'length' => 64,
94
			]);
95
			$table->setPrimaryKey(['applicable_id']);
96
			$table->addIndex(['mount_id'], 'applicable_mount');
97
			$table->addIndex(['type', 'value'], 'applicable_type_value');
98
			$table->addUniqueIndex(['type', 'value', 'mount_id'], 'applicable_type_value_mount');
99
		}
100
101
		if (!$schema->hasTable('external_config')) {
102
			$table = $schema->createTable('external_config');
103
			$table->addColumn('config_id', Types::BIGINT, [
104
				'autoincrement' => true,
105
				'notnull' => true,
106
				'length' => 6,
107
			]);
108
			$table->addColumn('mount_id', Types::BIGINT, [
109
				'notnull' => true,
110
				'length' => 6,
111
			]);
112
			$table->addColumn('key', Types::STRING, [
113
				'notnull' => true,
114
				'length' => 64,
115
			]);
116
			$table->addColumn('value', Types::STRING, [
117
				'notnull' => false,
118
				'length' => 4096,
119
			]);
120
			$table->setPrimaryKey(['config_id']);
121
			$table->addIndex(['mount_id'], 'config_mount');
122
			$table->addUniqueIndex(['mount_id', 'key'], 'config_mount_key');
123
		}
124
125
		if (!$schema->hasTable('external_options')) {
126
			$table = $schema->createTable('external_options');
127
			$table->addColumn('option_id', Types::BIGINT, [
128
				'autoincrement' => true,
129
				'notnull' => true,
130
				'length' => 6,
131
			]);
132
			$table->addColumn('mount_id', Types::BIGINT, [
133
				'notnull' => true,
134
				'length' => 6,
135
			]);
136
			$table->addColumn('key', Types::STRING, [
137
				'notnull' => true,
138
				'length' => 64,
139
			]);
140
			$table->addColumn('value', Types::STRING, [
141
				'notnull' => true,
142
				'length' => 256,
143
			]);
144
			$table->setPrimaryKey(['option_id']);
145
			$table->addIndex(['mount_id'], 'option_mount');
146
			$table->addUniqueIndex(['mount_id', 'key'], 'option_mount_key');
147
		}
148
		return $schema;
149
	}
150
}
151