|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace OCA\DAV\Migration; |
|
6
|
|
|
|
|
7
|
|
|
use Closure; |
|
8
|
|
|
use Doctrine\DBAL\Types\Type; |
|
9
|
|
|
use OCP\DB\ISchemaWrapper; |
|
10
|
|
|
use OCP\Migration\SimpleMigrationStep; |
|
11
|
|
|
use OCP\Migration\IOutput; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Auto-generated migration step: Please modify to your needs! |
|
15
|
|
|
*/ |
|
16
|
|
|
class Version1011Date20190725113607 extends SimpleMigrationStep { |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @param IOutput $output |
|
20
|
|
|
* @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
21
|
|
|
* @param array $options |
|
22
|
|
|
* @return null|ISchemaWrapper |
|
23
|
|
|
* @since 13.0.0 |
|
24
|
|
|
*/ |
|
25
|
|
|
public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
26
|
|
|
/** @var ISchemaWrapper $schema */ |
|
27
|
|
|
$schema = $schemaClosure(); |
|
28
|
|
|
|
|
29
|
|
|
$types = ['resource', 'room']; |
|
30
|
|
|
foreach($types as $type) { |
|
31
|
|
|
if (!$schema->hasTable($this->getMetadataTableName($type))) { |
|
32
|
|
|
$table = $schema->createTable($this->getMetadataTableName($type)); |
|
33
|
|
|
|
|
34
|
|
|
$table->addColumn('id', Type::BIGINT, [ |
|
35
|
|
|
'autoincrement' => true, |
|
36
|
|
|
'notnull' => true, |
|
37
|
|
|
'length' => 11, |
|
38
|
|
|
'unsigned' => true, |
|
39
|
|
|
]); |
|
40
|
|
|
$table->addColumn($type . '_id', Type::BIGINT, [ |
|
41
|
|
|
'notnull' => true, |
|
42
|
|
|
'length' => 11, |
|
43
|
|
|
'unsigned' => true, |
|
44
|
|
|
]); |
|
45
|
|
|
$table->addColumn('key', Type::STRING, [ |
|
46
|
|
|
'notnull' => true, |
|
47
|
|
|
'length' => 255, |
|
48
|
|
|
]); |
|
49
|
|
|
$table->addColumn('value', Type::STRING, [ |
|
50
|
|
|
'notnull' => false, |
|
51
|
|
|
'length' => 4000, |
|
52
|
|
|
]); |
|
53
|
|
|
|
|
54
|
|
|
$table->setPrimaryKey(['id']); |
|
55
|
|
|
$table->addIndex([$type . '_id', 'key'], $this->getMetadataTableName($type) . '_idk'); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return $schema; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param string $type |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
|
|
private function getMetadataTableName(string $type):string { |
|
67
|
|
|
return 'calendar_' . $type . 's_md'; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|