Passed
Pull Request — master (#875)
by Pauli
04:47 queued 02:19
created

Version010300Date20210731201941::changeSchema()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 173
Code Lines 123

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 4
eloc 123
c 5
b 0
f 0
nc 8
nop 3
dl 0
loc 173
rs 8

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' => false,
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' => false,
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' => false,
125
				'length' => 2048,
126
			]);
127
			$table->addColumn('mimetype', 'string', [
128
				'notnull' => false,
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('season', 'integer', [
153
				'notnull' => false,
154
			]);
155
			$table->addColumn('link_url', 'string', [
156
				'notnull' => false,
157
				'length' => 2048,
158
			]);
159
			$table->addColumn('published', 'datetime', [
160
				'notnull' => false,
161
			]);
162
			$table->addColumn('keywords', 'string', [
163
				'notnull' => false,
164
				'length' => 256,
165
			]);
166
			$table->addColumn('copyright', 'string', [
167
				'notnull' => false,
168
				'length' => 256,
169
			]);
170
			$table->addColumn('author', 'string', [
171
				'notnull' => false,
172
				'length' => 256,
173
			]);
174
			$table->addColumn('description', 'text', [
175
				'notnull' => false,
176
			]);
177
			$table->addColumn('starred', 'datetime', [
178
				'notnull' => false,
179
			]);
180
			$table->addColumn('created', 'datetime', [
181
				'notnull' => false,
182
			]);
183
			$table->addColumn('updated', 'datetime', [
184
				'notnull' => false,
185
			]);
186
			$table->setPrimaryKey(['id']);
187
			$table->addUniqueIndex(['guid_hash', 'channel_id', 'user_id'], 'music_podcast_episodes_index');
188
		}
189
190
		$table = $schema->getTable('music_bookmarks');
191
		if (!$table->hasColumn('type')) {
192
			$table->addColumn('type', 'integer', [
193
				'notnull' => true,
194
			]);
195
			$table->dropIndex('music_bookmarks_user_track');
196
			$table->dropColumn('track_id');
197
			$table->addColumn('entry_id', 'integer', [
198
				'notnull' => true,
199
			]);
200
			$table->addUniqueIndex(['user_id', 'type', 'entry_id'], 'music_bookmarks_index');
201
		}
202
203
		return $schema;
204
	}
205
206
	/**
207
	 * @param IOutput $output
208
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
209
	 * @param array $options
210
	 */
211
	public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
212
	}
213
}
214