Completed
Push — master ( fbedcb...7bca82 )
by Joas
02:11
created

Version2006Date20170808154933::postSchemaChange()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 2
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 3
crap 2
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Joas Schilling <[email protected]>
4
 *
5
 * @author Joas Schilling <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Activity\Migration;
25
26
use Doctrine\DBAL\Schema\Schema;
27
use OCP\Migration\SimpleMigrationStep;
28
use OCP\Migration\IOutput;
29
30
class Version2006Date20170808154933 extends SimpleMigrationStep {
31
32
	/**
33
	 * @param IOutput $output
34
	 * @param \Closure $schemaClosure The `\Closure` returns a `Schema`
35
	 * @param array $options
36
	 * @return null|Schema
37
	 * @since 13.0.0
38
	 */
39
	public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
40
		/** @var Schema $schema */
41
		$schema = $schemaClosure();
42
43
		if (!$schema->hasTable('activity')) {
44
			$table = $schema->createTable('activity');
45
			$table->addColumn('activity_id', 'integer', [
46
				'autoincrement' => true,
47
				'notnull' => true,
48
				'length' => 4,
49
			]);
50
			$table->addColumn('timestamp', 'integer', [
51
				'notnull' => true,
52
				'length' => 4,
53
				'default' => 0,
54
			]);
55
			$table->addColumn('priority', 'integer', [
56
				'notnull' => true,
57
				'length' => 4,
58
				'default' => 0,
59
			]);
60
			$table->addColumn('type', 'string', [
61
				'notnull' => false,
62
				'length' => 255,
63
			]);
64
			$table->addColumn('user', 'string', [
65
				'notnull' => false,
66
				'length' => 64,
67
			]);
68
			$table->addColumn('affecteduser', 'string', [
69
				'notnull' => true,
70
				'length' => 64,
71
			]);
72
			$table->addColumn('app', 'string', [
73
				'notnull' => true,
74
				'length' => 32,
75
			]);
76
			$table->addColumn('subject', 'string', [
77
				'notnull' => true,
78
				'length' => 255,
79
			]);
80
			$table->addColumn('subjectparams', 'text', [
81
				'notnull' => true,
82
			]);
83
			$table->addColumn('message', 'string', [
84
				'notnull' => false,
85
				'length' => 255,
86
			]);
87
			$table->addColumn('messageparams', 'text', [
88
				'notnull' => false,
89
			]);
90
			$table->addColumn('file', 'string', [
91
				'notnull' => false,
92
				'length' => 4000,
93
			]);
94
			$table->addColumn('link', 'string', [
95
				'notnull' => false,
96
				'length' => 4000,
97
			]);
98
			$table->addColumn('object_type', 'string', [
99
				'notnull' => false,
100
				'length' => 255,
101
			]);
102
			$table->addColumn('object_id', 'integer', [
103
				'notnull' => true,
104
				'length' => 4,
105
				'default' => 0,
106
			]);
107
			$table->setPrimaryKey(['activity_id']);
108
			$table->addIndex(['timestamp'], 'activity_time');
109
			$table->addIndex(['affecteduser', 'timestamp'], 'activity_user_time');
110
			$table->addIndex(['affecteduser', 'user', 'timestamp'], 'activity_filter_by');
111
			$table->addIndex(['affecteduser', 'app', 'timestamp'], 'activity_filter_app');
112
			$table->addIndex(['object_type', 'object_id'], 'activity_object');
113
		}
114
115
		if (!$schema->hasTable('activity_mq')) {
116
			$table = $schema->createTable('activity_mq');
117
			$table->addColumn('mail_id', 'integer', [
118
				'autoincrement' => true,
119
				'notnull' => true,
120
				'length' => 4,
121
			]);
122
			$table->addColumn('amq_timestamp', 'integer', [
123
				'notnull' => true,
124
				'length' => 4,
125
				'default' => 0,
126
			]);
127
			$table->addColumn('amq_latest_send', 'integer', [
128
				'notnull' => true,
129
				'length' => 4,
130
				'default' => 0,
131
			]);
132
			$table->addColumn('amq_type', 'string', [
133
				'notnull' => true,
134
				'length' => 255,
135
			]);
136
			$table->addColumn('amq_affecteduser', 'string', [
137
				'notnull' => true,
138
				'length' => 64,
139
			]);
140
			$table->addColumn('amq_appid', 'string', [
141
				'notnull' => true,
142
				'length' => 255,
143
			]);
144
			$table->addColumn('amq_subject', 'string', [
145
				'notnull' => true,
146
				'length' => 255,
147
			]);
148
			$table->addColumn('amq_subjectparams', 'string', [
149
				'notnull' => true,
150
				'length' => 4000,
151
			]);
152
			$table->setPrimaryKey(['mail_id']);
153
			$table->addIndex(['amq_affecteduser'], 'amp_user');
154
			$table->addIndex(['amq_latest_send'], 'amp_latest_send_time');
155
			$table->addIndex(['amq_timestamp'], 'amp_timestamp_time');
156
		}
157
		return $schema;
158
	}
159
160
}
161