Version3009Date20200630194059::changeSchema()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 49

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 49
ccs 0
cts 46
cp 0
rs 9.1127
c 0
b 0
f 0
cc 3
nc 4
nop 3
crap 12
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\AnnouncementCenter\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 Version3009Date20200630194059 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) {
42
		/** @var ISchemaWrapper $schema */
43
		$schema = $schemaClosure();
44
45
		if (!$schema->hasTable('announcements')) {
46
			$table = $schema->createTable('announcements');
47
			$table->addColumn('announcement_id', Types::INTEGER, [
48
				'autoincrement' => true,
49
				'notnull' => true,
50
				'length' => 4,
51
			]);
52
			$table->addColumn('announcement_time', Types::INTEGER, [
53
				'notnull' => true,
54
				'length' => 4,
55
				'default' => 0,
56
			]);
57
			$table->addColumn('announcement_user', Types::STRING, [
58
				'notnull' => true,
59
				'length' => 64,
60
			]);
61
			$table->addColumn('announcement_subject', Types::STRING, [
62
				'notnull' => true,
63
				'length' => 512,
64
			]);
65
			$table->addColumn('announcement_message', Types::TEXT, [
66
				'notnull' => false,
67
			]);
68
			$table->addColumn('allow_comments', Types::SMALLINT, [
69
				'notnull' => false,
70
				'length' => 1,
71
				'default' => 1,
72
			]);
73
			$table->setPrimaryKey(['announcement_id']);
74
		}
75
76
		if (!$schema->hasTable('announcements_groups')) {
77
			$table = $schema->createTable('announcements_groups');
78
			$table->addColumn('announcement_id', Types::INTEGER, [
79
				'notnull' => true,
80
				'length' => 4,
81
			]);
82
			$table->addColumn('gid', Types::STRING, [
83
				'notnull' => true,
84
				'length' => 64,
85
			]);
86
			$table->addUniqueIndex(['announcement_id', 'gid'], 'announce_group');
87
		}
88
		return $schema;
89
	}
90
}
91