Passed
Push — master ( 7ad038...6c6f41 )
by Morris
13:41 queued 10s
created

Version1010Date20200630191302   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 48
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A changeSchema() 0 40 2
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * @copyright Copyright (c) 2020 Joas Schilling <[email protected]>
6
 *
7
 * @author Joas Schilling <[email protected]>
8
 *
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
namespace OCA\Federation\Migration;
27
28
use Closure;
29
use Doctrine\DBAL\Types\Types;
30
use OCP\DB\ISchemaWrapper;
31
use OCP\Migration\IOutput;
32
use OCP\Migration\SimpleMigrationStep;
33
34
class Version1010Date20200630191302 extends SimpleMigrationStep {
35
36
	/**
37
	 * @param IOutput $output
38
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
39
	 * @param array $options
40
	 * @return null|ISchemaWrapper
41
	 */
42
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
43
		/** @var ISchemaWrapper $schema */
44
		$schema = $schemaClosure();
45
46
		if (!$schema->hasTable('trusted_servers')) {
47
			$table = $schema->createTable('trusted_servers');
48
			$table->addColumn('id', Types::INTEGER, [
49
				'autoincrement' => true,
50
				'notnull' => true,
51
				'length' => 4,
52
			]);
53
			$table->addColumn('url', Types::STRING, [
54
				'notnull' => true,
55
				'length' => 512,
56
			]);
57
			$table->addColumn('url_hash', Types::STRING, [
58
				'notnull' => true,
59
				'default' => '',
60
			]);
61
			$table->addColumn('token', Types::STRING, [
62
				'notnull' => false,
63
				'length' => 128,
64
			]);
65
			$table->addColumn('shared_secret', Types::STRING, [
66
				'notnull' => false,
67
				'length' => 256,
68
			]);
69
			$table->addColumn('status', Types::INTEGER, [
70
				'notnull' => true,
71
				'length' => 4,
72
				'default' => 2,
73
			]);
74
			$table->addColumn('sync_token', Types::STRING, [
75
				'notnull' => false,
76
				'length' => 512,
77
			]);
78
			$table->setPrimaryKey(['id']);
79
			$table->addUniqueIndex(['url_hash'], 'url_hash');
80
		}
81
		return $schema;
82
	}
83
}
84