Passed
Pull Request — master (#875)
by Pauli
11:55 queued 09:28
created

Version010300Date20210731201941::preSchemaChange()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 1
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 1
rs 10
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('last_build_date', 'datetime', [
65
				'notnull' => false,
66
			]);
67
			$table->addColumn('title', 'string', [
68
				'notnull' => false,
69
				'length' => 256,
70
			]);
71
			$table->addColumn('link_url', 'string', [
72
				'notnull' => false,
73
				'length' => 2048,
74
			]);
75
			$table->addColumn('language', 'string', [
76
				'notnull' => false,
77
				'length' => 32,
78
			]);
79
			$table->addColumn('copyright', 'string', [
80
				'notnull' => false,
81
				'length' => 256,
82
			]);
83
			$table->addColumn('author', 'string', [
84
				'notnull' => false,
85
				'length' => 256,
86
			]);
87
			$table->addColumn('description', 'text', [
88
				'notnull' => false,
89
			]);
90
			$table->addColumn('image_url', 'string', [
91
				'notnull' => false,
92
				'length' => 2048,
93
			]);
94
			$table->addColumn('category', 'string', [
95
				'notnull' => false,
96
				'length' => 256,
97
			]);
98
			$table->addColumn('starred', 'datetime', [
99
				'notnull' => false,
100
			]);
101
			$table->addColumn('created', 'datetime', [
102
				'notnull' => false,
103
			]);
104
			$table->addColumn('updated', 'datetime', [
105
				'notnull' => false,
106
			]);
107
			$table->setPrimaryKey(['id']);
108
			$table->addUniqueIndex(['rss_hash', 'user_id'], 'music_podcast_channels_index');
109
		}
110
111
		if (!$schema->hasTable('music_podcast_episodes')) {
112
			$table = $schema->createTable('music_podcast_episodes');
113
			$table->addColumn('id', 'integer', [
114
				'autoincrement' => true,
115
				'notnull' => true,
116
				'unsigned' => true,
117
			]);
118
			$table->addColumn('user_id', 'string', [
119
				'notnull' => true,
120
				'length' => 64,
121
			]);
122
			$table->addColumn('channel_id', 'integer', [
123
				'notnull' => true,
124
				'unsigned' => true,
125
			]);
126
			$table->addColumn('stream_url', 'string', [
127
				'notnull' => false,
128
				'length' => 2048,
129
			]);
130
			$table->addColumn('mimetype', 'string', [
131
				'notnull' => false,
132
				'length' => 256,
133
			]);
134
			$table->addColumn('size', 'integer', [
135
				'notnull' => false,
136
			]);
137
			$table->addColumn('duration', 'integer', [
138
				'notnull' => false,
139
			]);
140
			$table->addColumn('guid', 'string', [
141
				'notnull' => true,
142
				'length' => 2048,
143
			]);
144
			$table->addColumn('guid_hash', 'string', [
145
				'notnull' => true,
146
				'length' => 64,
147
			]);
148
			$table->addColumn('title', 'string', [
149
				'notnull' => false,
150
				'length' => 256,
151
			]);
152
			$table->addColumn('episode', 'integer', [
153
				'notnull' => false,
154
			]);
155
			$table->addColumn('season', 'integer', [
156
				'notnull' => false,
157
			]);
158
			$table->addColumn('link_url', 'string', [
159
				'notnull' => false,
160
				'length' => 2048,
161
			]);
162
			$table->addColumn('published', 'datetime', [
163
				'notnull' => false,
164
			]);
165
			$table->addColumn('keywords', 'string', [
166
				'notnull' => false,
167
				'length' => 256,
168
			]);
169
			$table->addColumn('copyright', 'string', [
170
				'notnull' => false,
171
				'length' => 256,
172
			]);
173
			$table->addColumn('author', 'string', [
174
				'notnull' => false,
175
				'length' => 256,
176
			]);
177
			$table->addColumn('description', 'text', [
178
				'notnull' => false,
179
			]);
180
			$table->addColumn('starred', 'datetime', [
181
				'notnull' => false,
182
			]);
183
			$table->addColumn('created', 'datetime', [
184
				'notnull' => false,
185
			]);
186
			$table->addColumn('updated', 'datetime', [
187
				'notnull' => false,
188
			]);
189
			$table->setPrimaryKey(['id']);
190
			$table->addUniqueIndex(['guid_hash', 'channel_id', 'user_id'], 'music_podcast_episodes_index');
191
		}
192
193
		$table = $schema->getTable('music_bookmarks');
194
		if (!$table->hasColumn('type')) {
195
			$table->addColumn('type', 'integer', [
196
				'notnull' => true,
197
			]);
198
			$table->dropIndex('music_bookmarks_user_track');
199
			$table->dropColumn('track_id');
200
			$table->addColumn('entry_id', 'integer', [
201
				'notnull' => true,
202
			]);
203
			$table->addUniqueIndex(['user_id', 'type', 'entry_id'], 'music_bookmarks_index');
204
		}
205
206
		return $schema;
207
	}
208
209
	/**
210
	 * @param IOutput $output
211
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
212
	 * @param array $options
213
	 */
214
	public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
215
	}
216
}
217