Passed
Push — master ( 902adb...3cf321 )
by Christoph
10:44 queued 11s
created

Version010000Date20200304152605   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 32
c 1
b 0
f 0
dl 0
loc 57
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A changeSchema() 0 48 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright 2020 Christoph Wurst <[email protected]>
7
 *
8
 * @author 2020 Christoph Wurst <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 */
25
26
namespace OCA\ContactsInteraction\Migration;
27
28
use Closure;
29
use OCA\ContactsInteraction\Db\RecentContactMapper;
30
use OCP\DB\ISchemaWrapper;
31
use OCP\Migration\IOutput;
32
use OCP\Migration\SimpleMigrationStep;
33
34
class Version010000Date20200304152605 extends SimpleMigrationStep {
35
36
	/**
37
	 * @param IOutput $output
38
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
39
	 * @param array $options
40
	 *
41
	 * @return ISchemaWrapper
42
	 */
43
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ISchemaWrapper {
44
		/** @var ISchemaWrapper $schema */
45
		$schema = $schemaClosure();
46
47
		$table = $schema->createTable(RecentContactMapper::TABLE_NAME);
48
		$table->addColumn('id', 'integer', [
49
			'autoincrement' => true,
50
			'notnull' => true,
51
			'length' => 4,
52
		]);
53
		$table->addColumn('actor_uid', 'string', [
54
			'notnull' => true,
55
			'length' => 64,
56
		]);
57
		$table->addColumn('uid', 'string', [
58
			'notnull' => false,
59
			'length' => 64,
60
		]);
61
		$table->addColumn('email', 'string', [
62
			'notnull' => false,
63
			'length' => 255,
64
		]);
65
		$table->addColumn('federated_cloud_id', 'string', [
66
			'notnull' => false,
67
			'length' => 255,
68
		]);
69
		$table->addColumn('card', 'blob', [
70
			'notnull' => true,
71
		]);
72
		$table->addColumn('last_contact', 'integer', [
73
			'notnull' => true,
74
			'length' => 4,
75
		]);
76
		$table->setPrimaryKey(['id']);
77
		// To find all recent entries
78
		$table->addIndex(['actor_uid'], RecentContactMapper::TABLE_NAME . '_actor_uid');
79
		// To find a specific entry
80
		$table->addIndex(['id', 'actor_uid'], RecentContactMapper::TABLE_NAME . '_id_uid');
81
		// To find all recent entries with a given UID
82
		$table->addIndex(['uid'], RecentContactMapper::TABLE_NAME . '_uid');
83
		// To find all recent entries with a given email address
84
		$table->addIndex(['email'], RecentContactMapper::TABLE_NAME . '_email');
85
		// To find all recent entries with a give federated cloud id
86
		$table->addIndex(['federated_cloud_id'], RecentContactMapper::TABLE_NAME . '_fed_id');
87
		// For the cleanup
88
		$table->addIndex(['last_contact'], RecentContactMapper::TABLE_NAME . '_last_contact');
89
90
		return $schema;
91
	}
92
93
}
94