Completed
Pull Request — master (#362)
by Maxence
01:57
created

Version0017Date20191210153032::changeSchema()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 9.264
c 0
b 0
f 0
cc 2
nc 2
nop 3
1
<?php declare(strict_types=1);
2
3
4
/**
5
 * Circles - Bring cloud-users closer together.
6
 *
7
 * This file is licensed under the Affero General Public License version 3 or
8
 * later. See the COPYING file.
9
 *
10
 * @author Maxence Lange <[email protected]>
11
 * @copyright 2019
12
 * @license GNU AGPL version 3 or any later version
13
 *
14
 * This program is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Affero General Public License as
16
 * published by the Free Software Foundation, either version 3 of the
17
 * License, or (at your option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU Affero General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Affero General Public License
25
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
 *
27
 */
28
29
30
namespace OCA\Circles\Migration;
31
32
33
use Closure;
34
use Doctrine\DBAL\Schema\SchemaException;
35
use OCP\DB\ISchemaWrapper;
36
use OCP\Migration\IOutput;
37
use OCP\Migration\SimpleMigrationStep;
38
39
40
class Version0017Date20191210153032 extends SimpleMigrationStep {
41
42
	/**
43
	 * @param IOutput $output
44
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
45
	 * @param array $options
46
	 */
47
	public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
48
	}
49
50
	/**
51
	 * @param IOutput $output
52
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
53
	 * @param array $options
54
	 *
55
	 * @return null|ISchemaWrapper
56
	 * @throws SchemaException
57
	 */
58
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
59
		/** @var ISchemaWrapper $schema */
60
		$schema = $schemaClosure();
61
62
		$table = $schema->getTable('circles_members');
63
		if (!$table->hasColumn('instance')) {
64
			$table->addColumn(
65
				'instance', 'string', [
66
							  'notnull' => false,
67
							  'length'  => 255,
68
						  ]
69
			);
70
		}
71
72
		$table = $schema->createTable('circles_gsevents');
73
		$table->addColumn(
74
			'token', 'string', [
75
					   'notnull' => false,
76
					   'length'  => 63,
77
				   ]
78
		);
79
		$table->addColumn(
80
			'event', 'text', [
81
					   'notnull' => false
82
				   ]
83
		);
84
		$table->addColumn(
85
			'instances', 'text', [
86
						   'notnull' => false
87
					   ]
88
		);
89
		$table->addColumn(
90
			'creation', 'bigint', [
91
						  'length'  => 14,
92
						  'notnull' => false
93
					  ]
94
		);
95
		$table->addUniqueIndex(['token']);
96
97
		return $schema;
98
	}
99
100
	/**
101
	 * @param IOutput $output
102
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
103
	 * @param array $options
104
	 */
105
	public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
106
	}
107
108
}
109
110