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

postSchemaChange()   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('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('created', 'datetime', [
96
				'notnull' => false,
97
			]);
98
			$table->addColumn('updated', 'datetime', [
99
				'notnull' => false,
100
			]);
101
			$table->setPrimaryKey(['id']);
102
			$table->addUniqueIndex(['rss_hash', 'user_id'], 'music_podcast_channels_index');
103
		}
104
105
		if (!$schema->hasTable('music_podcast_episodes')) {
106
			$table = $schema->createTable('music_podcast_episodes');
107
			$table->addColumn('id', 'integer', [
108
				'autoincrement' => true,
109
				'notnull' => true,
110
				'unsigned' => true,
111
			]);
112
			$table->addColumn('user_id', 'string', [
113
				'notnull' => true,
114
				'length' => 64,
115
			]);
116
			$table->addColumn('channel_id', 'integer', [
117
				'notnull' => true,
118
				'unsigned' => true,
119
			]);
120
			$table->addColumn('stream_url', 'string', [
121
				'notnull' => true,
122
				'length' => 2048,
123
			]);
124
			$table->addColumn('mimetype', 'string', [
125
				'notnull' => true,
126
				'length' => 256,
127
			]);
128
			$table->addColumn('size', 'integer', [
129
				'notnull' => false,
130
			]);
131
			$table->addColumn('duration', 'integer', [
132
				'notnull' => false,
133
			]);
134
			$table->addColumn('guid', 'string', [
135
				'notnull' => true,
136
				'length' => 2048,
137
			]);
138
			$table->addColumn('guid_hash', 'string', [
139
				'notnull' => true,
140
				'length' => 64,
141
			]);
142
			$table->addColumn('title', 'string', [
143
				'notnull' => false,
144
				'length' => 256,
145
			]);
146
			$table->addColumn('episode', 'integer', [
147
				'notnull' => false,
148
			]);
149
			$table->addColumn('link_url', 'string', [
150
				'notnull' => true,
151
				'length' => 2048,
152
			]);
153
			$table->addColumn('published', 'datetime', [
154
				'notnull' => false,
155
			]);
156
			$table->addColumn('keywords', 'string', [
157
				'notnull' => false,
158
				'length' => 256,
159
			]);
160
			$table->addColumn('copyright', 'string', [
161
				'notnull' => false,
162
				'length' => 256,
163
			]);
164
			$table->addColumn('author', 'string', [
165
				'notnull' => false,
166
				'length' => 256,
167
			]);
168
			$table->addColumn('description', 'text', [
169
				'notnull' => false,
170
			]);
171
			$table->addColumn('created', 'datetime', [
172
				'notnull' => false,
173
			]);
174
			$table->addColumn('updated', 'datetime', [
175
				'notnull' => false,
176
			]);
177
			$table->setPrimaryKey(['id']);
178
			$table->addUniqueIndex(['guid_hash', 'channel_id', 'user_id'], 'music_podcast_episodes_index');
179
		}
180
181
		return $schema;
182
	}
183
184
	/**
185
	 * @param IOutput $output
186
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
187
	 * @param array $options
188
	 */
189
	public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
190
	}
191
}
192