1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace OCA\audioplayer\Migration; |
6
|
|
|
|
7
|
|
|
use Closure; |
8
|
|
|
use OCP\DB\ISchemaWrapper; |
9
|
|
|
use OCP\Migration\IOutput; |
10
|
|
|
use OCP\Migration\SimpleMigrationStep; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Auto-generated migration step: Please modify to your needs! |
14
|
|
|
*/ |
15
|
|
|
class Version2102Date20200712193332 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('audioplayer_artists')) { |
36
|
|
|
$table = $schema->createTable('audioplayer_artists'); |
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('name', 'string', [ |
47
|
|
|
'notnull' => false, |
48
|
|
|
'length' => 256, |
49
|
|
|
]); |
50
|
|
|
$table->setPrimaryKey(['id']); |
51
|
|
|
$table->addIndex(['user_id'], 'artists_user_id_idx'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if (!$schema->hasTable('audioplayer_albums')) { |
55
|
|
|
$table = $schema->createTable('audioplayer_albums'); |
56
|
|
|
$table->addColumn('id', 'integer', [ |
57
|
|
|
'autoincrement' => true, |
58
|
|
|
'notnull' => true, |
59
|
|
|
'unsigned' => true, |
60
|
|
|
]); |
61
|
|
|
$table->addColumn('user_id', 'string', [ |
62
|
|
|
'notnull' => true, |
63
|
|
|
'length' => 64, |
64
|
|
|
]); |
65
|
|
|
$table->addColumn('name', 'string', [ |
66
|
|
|
'notnull' => false, |
67
|
|
|
'length' => 256, |
68
|
|
|
]); |
69
|
|
|
$table->addColumn('year', 'integer', [ |
70
|
|
|
'notnull' => false, |
71
|
|
|
'unsigned' => true, |
72
|
|
|
]); |
73
|
|
|
$table->addColumn('genre_id', 'integer', [ |
74
|
|
|
'notnull' => false, |
75
|
|
|
]); |
76
|
|
|
$table->addColumn('cover', 'text', [ |
77
|
|
|
'notnull' => false, |
78
|
|
|
]); |
79
|
|
|
$table->addColumn('bgcolor', 'string', [ |
80
|
|
|
'notnull' => false, |
81
|
|
|
'length' => 40, |
82
|
|
|
]); |
83
|
|
|
$table->addColumn('artist_id', 'integer', [ |
84
|
|
|
'notnull' => false, |
85
|
|
|
]); |
86
|
|
|
$table->addColumn('folder_id', 'integer', [ |
87
|
|
|
'notnull' => false, |
88
|
|
|
]); |
89
|
|
|
$table->setPrimaryKey(['id']); |
90
|
|
|
$table->addIndex(['user_id'], 'albums_user_id_idx'); |
91
|
|
|
$table->addIndex(['id', 'user_id'], 'albums_album_user_idx'); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
if (!$schema->hasTable('audioplayer_genre')) { |
95
|
|
|
$table = $schema->createTable('audioplayer_genre'); |
96
|
|
|
$table->addColumn('id', 'integer', [ |
97
|
|
|
'autoincrement' => true, |
98
|
|
|
'notnull' => true, |
99
|
|
|
'unsigned' => true, |
100
|
|
|
]); |
101
|
|
|
$table->addColumn('user_id', 'string', [ |
102
|
|
|
'notnull' => true, |
103
|
|
|
'length' => 64, |
104
|
|
|
]); |
105
|
|
|
$table->addColumn('name', 'string', [ |
106
|
|
|
'notnull' => false, |
107
|
|
|
'length' => 256, |
108
|
|
|
]); |
109
|
|
|
$table->setPrimaryKey(['id']); |
110
|
|
|
$table->addIndex(['user_id'], 'genre_user_id_idx'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
if (!$schema->hasTable('audioplayer_playlists')) { |
114
|
|
|
$table = $schema->createTable('audioplayer_playlists'); |
115
|
|
|
$table->addColumn('id', 'integer', [ |
116
|
|
|
'autoincrement' => true, |
117
|
|
|
'notnull' => true, |
118
|
|
|
'unsigned' => true, |
119
|
|
|
]); |
120
|
|
|
$table->addColumn('user_id', 'string', [ |
121
|
|
|
'notnull' => true, |
122
|
|
|
'length' => 64, |
123
|
|
|
]); |
124
|
|
|
$table->addColumn('name', 'string', [ |
125
|
|
|
'notnull' => false, |
126
|
|
|
'length' => 256, |
127
|
|
|
]); |
128
|
|
|
$table->setPrimaryKey(['id']); |
129
|
|
|
$table->addIndex(['user_id'], 'playlists_user_id_idx'); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
if (!$schema->hasTable('audioplayer_playlist_tracks')) { |
133
|
|
|
$table = $schema->createTable('audioplayer_playlist_tracks'); |
134
|
|
|
$table->addColumn('playlist_id', 'integer', [ |
135
|
|
|
'notnull' => true, |
136
|
|
|
'unsigned' => true, |
137
|
|
|
]); |
138
|
|
|
$table->addColumn('track_id', 'integer', [ |
139
|
|
|
'notnull' => true, |
140
|
|
|
'unsigned' => true, |
141
|
|
|
]); |
142
|
|
|
$table->addColumn('sortorder', 'smallint', [ |
143
|
|
|
'notnull' => true, |
144
|
|
|
'length' => 1, |
145
|
|
|
'default' => 0, |
146
|
|
|
'unsigned' => true, |
147
|
|
|
]); |
148
|
|
|
$table->addIndex(['playlist_id'], 'playlist_tracks_idx'); |
149
|
|
|
$table->addUniqueIndex(['playlist_id', 'track_id'], 'playlist_tracks_unique_idx'); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
if (!$schema->hasTable('audioplayer_tracks')) { |
153
|
|
|
$table = $schema->createTable('audioplayer_tracks'); |
154
|
|
|
$table->addColumn('id', 'integer', [ |
155
|
|
|
'autoincrement' => true, |
156
|
|
|
'notnull' => true, |
157
|
|
|
'unsigned' => true, |
158
|
|
|
]); |
159
|
|
|
$table->addColumn('user_id', 'string', [ |
160
|
|
|
'notnull' => true, |
161
|
|
|
'length' => 64, |
162
|
|
|
]); |
163
|
|
|
$table->addColumn('title', 'string', [ |
164
|
|
|
'notnull' => true, |
165
|
|
|
'length' => 256, |
166
|
|
|
]); |
167
|
|
|
$table->addColumn('number', 'integer', [ |
168
|
|
|
'notnull' => false, |
169
|
|
|
'unsigned' => true, |
170
|
|
|
]); |
171
|
|
|
$table->addColumn('artist_id', 'integer', [ |
172
|
|
|
'notnull' => false, |
173
|
|
|
]); |
174
|
|
|
$table->addColumn('album_id', 'integer', [ |
175
|
|
|
'notnull' => false, |
176
|
|
|
]); |
177
|
|
|
$table->addColumn('length', 'string', [ |
178
|
|
|
'notnull' => true, |
179
|
|
|
'length' => 50, |
180
|
|
|
]); |
181
|
|
|
$table->addColumn('file_id', 'integer', [ |
182
|
|
|
'notnull' => true, |
183
|
|
|
]); |
184
|
|
|
$table->addColumn('bitrate', 'integer', [ |
185
|
|
|
'notnull' => false, |
186
|
|
|
'unsigned' => true, |
187
|
|
|
]); |
188
|
|
|
$table->addColumn('mimetype', 'string', [ |
189
|
|
|
'notnull' => true, |
190
|
|
|
'length' => 256, |
191
|
|
|
]); |
192
|
|
|
$table->addColumn('genre_id', 'integer', [ |
193
|
|
|
'notnull' => false, |
194
|
|
|
]); |
195
|
|
|
$table->addColumn('year', 'integer', [ |
196
|
|
|
'notnull' => false, |
197
|
|
|
'unsigned' => true, |
198
|
|
|
]); |
199
|
|
|
$table->addColumn('folder_id', 'integer', [ |
200
|
|
|
'notnull' => false, |
201
|
|
|
]); |
202
|
|
|
$table->addColumn('disc', 'integer', [ |
203
|
|
|
'notnull' => false, |
204
|
|
|
'unsigned' => true, |
205
|
|
|
]); |
206
|
|
|
$table->addColumn('composer', 'string', [ |
207
|
|
|
'notnull' => false, |
208
|
|
|
'length' => 256, |
209
|
|
|
]); |
210
|
|
|
$table->addColumn('subtitle', 'string', [ |
211
|
|
|
'notnull' => false, |
212
|
|
|
'length' => 256, |
213
|
|
|
]); |
214
|
|
|
$table->addColumn('isrc', 'string', [ |
215
|
|
|
'notnull' => false, |
216
|
|
|
'length' => 12, |
217
|
|
|
]); |
218
|
|
|
$table->addColumn('copyright', 'string', [ |
219
|
|
|
'notnull' => false, |
220
|
|
|
'length' => 256, |
221
|
|
|
]); |
222
|
|
|
$table->setPrimaryKey(['id']); |
223
|
|
|
$table->addIndex(['artist_id', 'user_id'], 'tracks_artist_id_idx'); |
224
|
|
|
$table->addIndex(['genre_id', 'user_id'], 'tracks_genre_id_idx'); |
225
|
|
|
$table->addIndex(['year', 'user_id'], 'tracks_year_idx'); |
226
|
|
|
$table->addIndex(['album_id', 'user_id'], 'tracks_album_id_idx'); |
227
|
|
|
$table->addIndex(['user_id'], 'tracks_user_id_idx'); |
228
|
|
|
$table->addIndex(['folder_id', 'user_id'], 'tracks_folder_id_idx'); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
if (!$schema->hasTable('audioplayer_streams')) { |
232
|
|
|
$table = $schema->createTable('audioplayer_streams'); |
233
|
|
|
$table->addColumn('id', 'integer', [ |
234
|
|
|
'autoincrement' => true, |
235
|
|
|
'notnull' => true, |
236
|
|
|
'unsigned' => true, |
237
|
|
|
]); |
238
|
|
|
$table->addColumn('user_id', 'string', [ |
239
|
|
|
'notnull' => true, |
240
|
|
|
'length' => 64, |
241
|
|
|
]); |
242
|
|
|
$table->addColumn('title', 'string', [ |
243
|
|
|
'notnull' => true, |
244
|
|
|
'length' => 256, |
245
|
|
|
]); |
246
|
|
|
$table->addColumn('file_id', 'integer', [ |
247
|
|
|
'notnull' => true, |
248
|
|
|
]); |
249
|
|
|
$table->addColumn('mimetype', 'string', [ |
250
|
|
|
'notnull' => true, |
251
|
|
|
'length' => 256, |
252
|
|
|
]); |
253
|
|
|
$table->setPrimaryKey(['id']); |
254
|
|
|
$table->addIndex(['user_id'], 'streams_user_id_idx'); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
if (!$schema->hasTable('audioplayer_stats')) { |
258
|
|
|
$table = $schema->createTable('audioplayer_stats'); |
259
|
|
|
$table->addColumn('id', 'integer', [ |
260
|
|
|
'autoincrement' => true, |
261
|
|
|
'notnull' => true, |
262
|
|
|
'unsigned' => true, |
263
|
|
|
]); |
264
|
|
|
$table->addColumn('user_id', 'string', [ |
265
|
|
|
'notnull' => true, |
266
|
|
|
'length' => 64, |
267
|
|
|
]); |
268
|
|
|
$table->addColumn('track_id', 'integer', [ |
269
|
|
|
'notnull' => true, |
270
|
|
|
]); |
271
|
|
|
$table->addColumn('playtime', 'integer', [ |
272
|
|
|
'notnull' => false, |
273
|
|
|
]); |
274
|
|
|
$table->addColumn('playcount', 'integer', [ |
275
|
|
|
'notnull' => false, |
276
|
|
|
]); |
277
|
|
|
$table->setPrimaryKey(['id']); |
278
|
|
|
$table->addUniqueIndex(['track_id', 'user_id'], 'stats_file_user_id_idx'); |
279
|
|
|
} |
280
|
|
|
return $schema; |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @param IOutput $output |
285
|
|
|
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
286
|
|
|
* @param array $options |
287
|
|
|
*/ |
288
|
|
|
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { |
289
|
|
|
} |
290
|
|
|
} |