Passed
Pull Request — master (#875)
by Pauli
04:17 queued 01:56
created

Version010300Date20210731201941::changeSchema()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 170
Code Lines 121

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 4
eloc 121
nc 8
nop 3
dl 0
loc 170
rs 8
c 3
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
declare(strict_types=1);
4
5
namespace OCA\Music\Migration;
6
7
use Closure;
8
use OCP\DB\ISchemaWrapper;
9
use OCP\Migration\SimpleMigrationStep;
10
use OCP\Migration\IOutput;
11
12
/**
13
 * Migration from 1.2.x to 1.3.0
14
 */
15
class Version010300Date20210731201941 extends SimpleMigrationStep {
16
17
	/**
18
	 * @param IOutput $output
19
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
20
	 * @param array $options
21
	 */
22
	public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
23
	}
24
25
	/**
26
	 * @param IOutput $output
27
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
28
	 * @param array $options
29
	 * @return null|ISchemaWrapper
30
	 */
31
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
32
		/** @var ISchemaWrapper $schema */
33
		$schema = $schemaClosure();
34
35
		if (!$schema->hasTable('music_podcast_channels')) {
36
			$table = $schema->createTable('music_podcast_channels');
37
			$table->addColumn('id', 'integer', [
38
				'autoincrement' => true,
39
				'notnull' => true,
40
				'unsigned' => true,
41
			]);
42
			$table->addColumn('user_id', 'string', [
43
				'notnull' => true,
44
				'length' => 64,
45
			]);
46
			$table->addColumn('rss_url', 'string', [
47
				'notnull' => true,
48
				'length' => 2048,
49
			]);
50
			$table->addColumn('rss_hash', 'string', [
51
				'notnull' => true,
52
				'length' => 64,
53
			]);
54
			$table->addColumn('content_hash', 'string', [
55
				'notnull' => true,
56
				'length' => 64,
57
			]);
58
			$table->addColumn('update_checked', 'datetime', [
59
				'notnull' => true,
60
			]);
61
			$table->addColumn('published', 'datetime', [
62
				'notnull' => false,
63
			]);
64
			$table->addColumn('title', 'string', [
65
				'notnull' => false,
66
				'length' => 256,
67
			]);
68
			$table->addColumn('link_url', 'string', [
69
				'notnull' => true,
70
				'length' => 2048,
71
			]);
72
			$table->addColumn('language', 'string', [
73
				'notnull' => false,
74
				'length' => 32,
75
			]);
76
			$table->addColumn('copyright', 'string', [
77
				'notnull' => false,
78
				'length' => 256,
79
			]);
80
			$table->addColumn('author', 'string', [
81
				'notnull' => false,
82
				'length' => 256,
83
			]);
84
			$table->addColumn('description', 'text', [
85
				'notnull' => false,
86
			]);
87
			$table->addColumn('image_url', 'string', [
88
				'notnull' => true,
89
				'length' => 2048,
90
			]);
91
			$table->addColumn('category', 'string', [
92
				'notnull' => false,
93
				'length' => 256,
94
			]);
95
			$table->addColumn('starred', 'datetime', [
96
				'notnull' => false,
97
			]);
98
			$table->addColumn('created', 'datetime', [
99
				'notnull' => false,
100
			]);
101
			$table->addColumn('updated', 'datetime', [
102
				'notnull' => false,
103
			]);
104
			$table->setPrimaryKey(['id']);
105
			$table->addUniqueIndex(['rss_hash', 'user_id'], 'music_podcast_channels_index');
106
		}
107
108
		if (!$schema->hasTable('music_podcast_episodes')) {
109
			$table = $schema->createTable('music_podcast_episodes');
110
			$table->addColumn('id', 'integer', [
111
				'autoincrement' => true,
112
				'notnull' => true,
113
				'unsigned' => true,
114
			]);
115
			$table->addColumn('user_id', 'string', [
116
				'notnull' => true,
117
				'length' => 64,
118
			]);
119
			$table->addColumn('channel_id', 'integer', [
120
				'notnull' => true,
121
				'unsigned' => true,
122
			]);
123
			$table->addColumn('stream_url', 'string', [
124
				'notnull' => true,
125
				'length' => 2048,
126
			]);
127
			$table->addColumn('mimetype', 'string', [
128
				'notnull' => true,
129
				'length' => 256,
130
			]);
131
			$table->addColumn('size', 'integer', [
132
				'notnull' => false,
133
			]);
134
			$table->addColumn('duration', 'integer', [
135
				'notnull' => false,
136
			]);
137
			$table->addColumn('guid', 'string', [
138
				'notnull' => true,
139
				'length' => 2048,
140
			]);
141
			$table->addColumn('guid_hash', 'string', [
142
				'notnull' => true,
143
				'length' => 64,
144
			]);
145
			$table->addColumn('title', 'string', [
146
				'notnull' => false,
147
				'length' => 256,
148
			]);
149
			$table->addColumn('episode', 'integer', [
150
				'notnull' => false,
151
			]);
152
			$table->addColumn('link_url', 'string', [
153
				'notnull' => true,
154
				'length' => 2048,
155
			]);
156
			$table->addColumn('published', 'datetime', [
157
				'notnull' => false,
158
			]);
159
			$table->addColumn('keywords', 'string', [
160
				'notnull' => false,
161
				'length' => 256,
162
			]);
163
			$table->addColumn('copyright', 'string', [
164
				'notnull' => false,
165
				'length' => 256,
166
			]);
167
			$table->addColumn('author', 'string', [
168
				'notnull' => false,
169
				'length' => 256,
170
			]);
171
			$table->addColumn('description', 'text', [
172
				'notnull' => false,
173
			]);
174
			$table->addColumn('starred', 'datetime', [
175
				'notnull' => false,
176
			]);
177
			$table->addColumn('created', 'datetime', [
178
				'notnull' => false,
179
			]);
180
			$table->addColumn('updated', 'datetime', [
181
				'notnull' => false,
182
			]);
183
			$table->setPrimaryKey(['id']);
184
			$table->addUniqueIndex(['guid_hash', 'channel_id', 'user_id'], 'music_podcast_episodes_index');
185
		}
186
187
		$table = $schema->getTable('music_bookmarks');
188
		if (!$table->hasColumn('type')) {
189
			$table->addColumn('type', 'integer', [
190
				'notnull' => true,
191
			]);
192
			$table->dropIndex('music_bookmarks_user_track');
193
			$table->dropColumn('track_id');
194
			$table->addColumn('entry_id', 'integer', [
195
				'notnull' => true,
196
			]);
197
			$table->addUniqueIndex(['user_id', 'type', 'entry_id'], 'music_bookmarks_index');
198
		}
199
200
		return $schema;
201
	}
202
203
	/**
204
	 * @param IOutput $output
205
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
206
	 * @param array $options
207
	 */
208
	public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
209
	}
210
}
211