Completed
Push — master ( 47b2ba...97e8f3 )
by Thomas
27s
created

Version20170111103310::changeSchema()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 111
Code Lines 80

Duplication

Lines 48
Ratio 43.24 %

Importance

Changes 0
Metric Value
cc 5
eloc 80
nc 16
nop 2
dl 48
loc 111
rs 8.1463
c 0
b 0
f 0

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
namespace OC\Migrations;
4
5
use Doctrine\DBAL\Schema\Schema;
6
use OCP\Migration\ISchemaMigration;
7
8
/**
9
 * Initial DB creation for external storages
10
 */
11
class Version20170111103310 implements ISchemaMigration {
12
13
	public function changeSchema(Schema $schema, array $options) {
14
		$prefix = $options['tablePrefix'];
15
		if (!$schema->hasTable("${prefix}external_mounts")) {
16
			$table = $schema->createTable("${prefix}external_mounts");
17
			$table->addColumn('mount_id', 'bigint', [
18
				'autoincrement' => true,
19
				'notnull' => true,
20
				'length' => 20,
21
			]);
22
			$table->addColumn('mount_point', 'string', [
23
				'notnull' => true,
24
				'length' => 128,
25
			]);
26
			$table->addColumn('storage_backend', 'string', [
27
				'notnull' => true,
28
				'length' => 64,
29
			]);
30
			$table->addColumn('auth_backend', 'string', [
31
				'notnull' => true,
32
				'length' => 64,
33
			]);
34
			$table->addColumn('priority', 'integer', [
35
				'notnull' => true,
36
				'length' => 4,
37
				'default' => 100,
38
			]);
39
			// admin = 1, personal = 2
40
			$table->addColumn('type', 'integer', [
41
				'notnull' => true,
42
				'length' => 4,
43
			]);
44
			$table->setPrimaryKey(['mount_id']);
45
		}
46
47
		if (!$schema->hasTable("${prefix}external_applicable")) {
48
			$table = $schema->createTable("${prefix}external_applicable");
49
			$table->addColumn('applicable_id', 'bigint', [
50
				'autoincrement' => true,
51
				'notnull' => true,
52
				'length' => 20,
53
			]);
54
			// foreign key: external_mounts.mount_id
55
			$table->addColumn('mount_id', 'bigint', [
56
				'notnull' => true,
57
				'length' => 20,
58
			]);
59
			// possible mount types: global = 1, group = 2, user = 3
60
			$table->addColumn('type', 'integer', [
61
				'notnull' => true,
62
				'length' => 4,
63
			]);
64
			$table->addColumn('value', 'string', [
65
				'notnull' => false,
66
				'length' => 64,
67
			]);
68
			$table->setPrimaryKey(['applicable_id']);
69
			$table->addIndex(['mount_id'], 'applicable_mount');
70
			$table->addIndex(['type', 'value'], 'applicable_type_value');
71
			$table->addUniqueIndex(['type', 'value', 'mount_id'], 'applicable_type_value_mount');
72
		}
73
74 View Code Duplication
		if (!$schema->hasTable("${prefix}external_config")) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
			$table = $schema->createTable("${prefix}external_config");
76
			$table->addColumn('config_id', 'bigint', [
77
				'autoincrement' => true,
78
				'notnull' => true,
79
				'length' => 20,
80
			]);
81
			// foreign key: external_mounts.mount_id
82
			$table->addColumn('mount_id', 'bigint', [
83
				'notnull' => true,
84
				'length' => 20,
85
			]);
86
			$table->addColumn('key', 'string', [
87
				'notnull' => true,
88
				'length' => 64,
89
			]);
90
			$table->addColumn('value', 'string', [
91
				'notnull' => true,
92
				'length' => 4096,
93
			]);
94
			$table->setPrimaryKey(['config_id']);
95
			$table->addIndex(['mount_id'], 'config_mount');
96
			$table->addUniqueIndex(['mount_id', 'key'], 'config_mount_key');
97
		}
98
99 View Code Duplication
		if (!$schema->hasTable("${prefix}external_options")) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
			$table = $schema->createTable("${prefix}external_options");
101
			$table->addColumn('option_id', 'bigint', [
102
				'autoincrement' => true,
103
				'notnull' => true,
104
				'length' => 20,
105
			]);
106
			// foreign key: external_mounts.mount_id
107
			$table->addColumn('mount_id', 'bigint', [
108
				'notnull' => true,
109
				'length' => 20,
110
			]);
111
			$table->addColumn('key', 'string', [
112
				'notnull' => true,
113
				'length' => 64,
114
			]);
115
			$table->addColumn('value', 'string', [
116
				'notnull' => true,
117
				'length' => 256,
118
			]);
119
			$table->setPrimaryKey(['option_id']);
120
			$table->addIndex(['mount_id'], 'option_mount');
121
			$table->addUniqueIndex(['mount_id', 'key'], 'option_mount_key');
122
		}
123
	}
124
}
125