Passed
Push — master ( fda6ff...86a3b7 )
by Joas
16:22 queued 12s
created

Version21000Date20201202095923   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A changeSchema() 0 33 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 OC\Core\Migrations;
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 Version21000Date20201202095923 extends SimpleMigrationStep {
35
	/**
36
	 * @param IOutput $output
37
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
38
	 * @param array $options
39
	 * @return null|ISchemaWrapper
40
	 */
41
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
42
		/** @var ISchemaWrapper $schema */
43
		$schema = $schemaClosure();
44
45
		if (!$schema->hasTable('accounts_data')) {
46
			$table = $schema->createTable('accounts_data');
47
			$table->addColumn('id', Types::BIGINT, [
48
				'autoincrement' => true,
49
				'notnull' => true,
50
				'length' => 20,
51
			]);
52
			$table->addColumn('uid', Types::STRING, [
53
				'notnull' => true,
54
				'length' => 64,
55
			]);
56
			$table->addColumn('name', Types::STRING, [
57
				'notnull' => true,
58
				'length' => 64,
59
			]);
60
			$table->addColumn('value', Types::STRING, [
61
				'notnull' => false,
62
				'length' => 255,
63
				'default' => '',
64
			]);
65
			$table->setPrimaryKey(['id']);
66
			$table->addIndex(['uid'], 'accounts_data_uid');
67
			$table->addIndex(['name'], 'accounts_data_name');
68
			$table->addIndex(['value'], 'accounts_data_value');
69
70
			return $schema;
71
		}
72
73
		return null;
74
	}
75
}
76