Completed
Push — master ( 7f194b...f212c6 )
by Morris
18:03 queued 13s
created

Version1005Date20180413093149::changeSchema()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 40
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

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