Skip to content

Commit 97f2cd5

Browse files
committed
Restore migration.
Signed-off-by: antoonp <antoon@redblom.com>
1 parent 8357f29 commit 97f2cd5

1 file changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\CloudFederationAPI\Migration;
11+
12+
use Closure;
13+
use OCP\DB\ISchemaWrapper;
14+
use OCP\DB\Types;
15+
use OCP\Migration\Attributes\CreateTable;
16+
use OCP\Migration\IOutput;
17+
use OCP\Migration\SimpleMigrationStep;
18+
19+
#[CreateTable(table: 'federated_invites', columns: ['id', 'user_id', 'recipient_provider', 'recipient_user_id', 'recipient_name', 'recipient_email', 'token', 'accepted', 'created_at', 'expired_at', 'accepted_at'], description: 'Supporting the OCM Invitation Flow feature')]
20+
class Version1016Date202502262004 extends SimpleMigrationStep {
21+
/**
22+
* @param IOutput $output
23+
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
24+
* @param array $options
25+
* @return null|ISchemaWrapper
26+
*/
27+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
28+
/** @var ISchemaWrapper $schema */
29+
$schema = $schemaClosure();
30+
$table_name = 'federated_invites';
31+
32+
if (!$schema->hasTable($table_name)) {
33+
$table = $schema->createTable($table_name);
34+
$table->addColumn('id', Types::BIGINT, [
35+
'autoincrement' => true,
36+
'notnull' => true,
37+
'length' => 11,
38+
'unsigned' => true,
39+
]);
40+
$table->addColumn('user_id', Types::STRING, [
41+
'notnull' => true,
42+
'length' => 64,
43+
44+
]);
45+
// https://saturncloud.io/blog/what-is-the-maximum-length-of-a-url-in-different-browsers/#maximum-url-length-in-different-browsers
46+
// We use the least common denominator, the minimum length supported by browsers
47+
$table->addColumn('recipient_provider', Types::STRING, [
48+
'notnull' => false,
49+
'length' => 2083,
50+
]);
51+
$table->addColumn('recipient_user_id', Types::STRING, [
52+
'notnull' => false,
53+
'length' => 1024,
54+
]);
55+
$table->addColumn('recipient_name', Types::STRING, [
56+
'notnull' => false,
57+
'length' => 1024,
58+
]);
59+
// https://www.directedignorance.com/blog/maximum-length-of-email-address
60+
$table->addColumn('recipient_email', Types::STRING, [
61+
'notnull' => false,
62+
'length' => 320,
63+
]);
64+
$table->addColumn('token', Types::STRING, [
65+
'notnull' => true,
66+
'length' => 60,
67+
]);
68+
$table->addColumn('accepted', Types::BOOLEAN, [
69+
'notnull' => false,
70+
'default' => false
71+
]);
72+
$table->addColumn('created_at', Types::BIGINT, [
73+
'notnull' => true,
74+
]);
75+
76+
$table->addColumn('expired_at', Types::BIGINT, [
77+
'notnull' => false,
78+
]);
79+
80+
$table->addColumn('accepted_at', Types::BIGINT, [
81+
'notnull' => false,
82+
]);
83+
84+
$table->addUniqueConstraint(['token']);
85+
$table->setPrimaryKey(['id']);
86+
return $schema;
87+
}
88+
89+
return null;
90+
}
91+
}

0 commit comments

Comments
 (0)