1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (c) 2019 Joas Schilling <[email protected]> |
5
|
|
|
* |
6
|
|
|
* @license GNU AGPL version 3 or any later version |
7
|
|
|
* |
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU Affero General Public License as |
10
|
|
|
* published by the Free Software Foundation, either version 3 of the |
11
|
|
|
* License, or (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU Affero General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU Affero General Public License |
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
namespace OCA\Notifications\Migration; |
24
|
|
|
|
25
|
|
|
use Closure; |
26
|
|
|
use Doctrine\DBAL\Types\Type; |
27
|
|
|
use OCP\DB\ISchemaWrapper; |
28
|
|
|
use OCP\Migration\SimpleMigrationStep; |
29
|
|
|
use OCP\Migration\IOutput; |
30
|
|
|
|
31
|
|
|
class Version2004Date20190107135757 extends SimpleMigrationStep { |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param IOutput $output |
35
|
|
|
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
36
|
|
|
* @param array $options |
37
|
|
|
* @return null|ISchemaWrapper |
38
|
|
|
*/ |
39
|
|
|
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { |
40
|
|
|
/** @var ISchemaWrapper $schema */ |
41
|
|
|
$schema = $schemaClosure(); |
42
|
|
|
|
43
|
|
|
if (!$schema->hasTable('notifications')) { |
44
|
|
|
$table = $schema->createTable('notifications'); |
45
|
|
|
$table->addColumn('notification_id', Type::INTEGER, [ |
46
|
|
|
'autoincrement' => true, |
47
|
|
|
'notnull' => true, |
48
|
|
|
'length' => 4, |
49
|
|
|
]); |
50
|
|
|
$table->addColumn('app', Type::STRING, [ |
51
|
|
|
'notnull' => true, |
52
|
|
|
'length' => 32, |
53
|
|
|
]); |
54
|
|
|
$table->addColumn('user', Type::STRING, [ |
55
|
|
|
'notnull' => true, |
56
|
|
|
'length' => 64, |
57
|
|
|
]); |
58
|
|
|
$table->addColumn('timestamp', Type::INTEGER, [ |
59
|
|
|
'notnull' => true, |
60
|
|
|
'length' => 4, |
61
|
|
|
'default' => 0, |
62
|
|
|
]); |
63
|
|
|
$table->addColumn('object_type', Type::STRING, [ |
64
|
|
|
'notnull' => true, |
65
|
|
|
'length' => 64, |
66
|
|
|
]); |
67
|
|
|
$table->addColumn('object_id', Type::STRING, [ |
68
|
|
|
'notnull' => true, |
69
|
|
|
'length' => 64, |
70
|
|
|
]); |
71
|
|
|
$table->addColumn('subject', Type::STRING, [ |
72
|
|
|
'notnull' => true, |
73
|
|
|
'length' => 64, |
74
|
|
|
]); |
75
|
|
|
$table->addColumn('subject_parameters', Type::TEXT, [ |
76
|
|
|
'notnull' => false, |
77
|
|
|
]); |
78
|
|
|
$table->addColumn('message', Type::STRING, [ |
79
|
|
|
'notnull' => false, |
80
|
|
|
'length' => 64, |
81
|
|
|
]); |
82
|
|
|
$table->addColumn('message_parameters', Type::TEXT, [ |
83
|
|
|
'notnull' => false, |
84
|
|
|
]); |
85
|
|
|
$table->addColumn('link', Type::STRING, [ |
86
|
|
|
'notnull' => false, |
87
|
|
|
'length' => 4000, |
88
|
|
|
]); |
89
|
|
|
$table->addColumn('icon', Type::STRING, [ |
90
|
|
|
'notnull' => false, |
91
|
|
|
'length' => 4000, |
92
|
|
|
]); |
93
|
|
|
$table->addColumn('actions', Type::TEXT, [ |
94
|
|
|
'notnull' => false, |
95
|
|
|
]); |
96
|
|
|
$table->setPrimaryKey(['notification_id']); |
97
|
|
|
$table->addIndex(['app'], 'oc_notifications_app'); |
98
|
|
|
$table->addIndex(['user'], 'oc_notifications_user'); |
99
|
|
|
$table->addIndex(['timestamp'], 'oc_notifications_timestamp'); |
100
|
|
|
$table->addIndex(['object_type', 'object_id'], 'oc_notifications_object'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if (!$schema->hasTable('notifications_pushtokens')) { |
104
|
|
|
$table = $schema->createTable('notifications_pushtokens'); |
105
|
|
|
$table->addColumn('uid', Type::STRING, [ |
106
|
|
|
'notnull' => true, |
107
|
|
|
'length' => 64, |
108
|
|
|
]); |
109
|
|
|
$table->addColumn('token', Type::INTEGER, [ |
110
|
|
|
'notnull' => true, |
111
|
|
|
'length' => 4, |
112
|
|
|
'default' => 0, |
113
|
|
|
]); |
114
|
|
|
$table->addColumn('deviceidentifier', Type::STRING, [ |
115
|
|
|
'notnull' => true, |
116
|
|
|
'length' => 128, |
117
|
|
|
]); |
118
|
|
|
$table->addColumn('devicepublickey', Type::STRING, [ |
119
|
|
|
'notnull' => true, |
120
|
|
|
'length' => 512, |
121
|
|
|
]); |
122
|
|
|
$table->addColumn('devicepublickeyhash', Type::STRING, [ |
123
|
|
|
'notnull' => true, |
124
|
|
|
'length' => 128, |
125
|
|
|
]); |
126
|
|
|
$table->addColumn('pushtokenhash', Type::STRING, [ |
127
|
|
|
'notnull' => true, |
128
|
|
|
'length' => 128, |
129
|
|
|
]); |
130
|
|
|
$table->addColumn('proxyserver', Type::STRING, [ |
131
|
|
|
'notnull' => true, |
132
|
|
|
'length' => 256, |
133
|
|
|
]); |
134
|
|
|
$table->addColumn('apptype', Type::STRING, [ |
135
|
|
|
'notnull' => true, |
136
|
|
|
'length' => 32, |
137
|
|
|
'default' => 'unknown', |
138
|
|
|
]); |
139
|
|
|
$table->addUniqueIndex(['uid', 'token'], 'oc_notifpushtoken'); |
140
|
|
|
} |
141
|
|
|
return $schema; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
} |
145
|
|
|
|