-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVersion1000Date20260309120000.php
More file actions
108 lines (98 loc) · 3.09 KB
/
Version1000Date20260309120000.php
File metadata and controls
108 lines (98 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* SPDX-FileCopyrightText: 2026 LibreCode coop and LibreCode contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
declare(strict_types=1);
namespace OCA\ProfileFields\Migration;
use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
class Version1000Date20260309120000 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
#[\Override]
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if (!$schema->hasTable('profile_fields_definitions')) {
$table = $schema->createTable('profile_fields_definitions');
$table->addColumn('id', Types::BIGINT, [
'autoincrement' => true,
'unsigned' => true,
]);
$table->addColumn('field_key', Types::STRING, [
'length' => 64,
]);
$table->addColumn('label', Types::STRING, [
'length' => 255,
]);
$table->addColumn('type', Types::STRING, [
'length' => 32,
]);
$table->addColumn('edit_policy', Types::STRING, [
'length' => 32,
'default' => 'users',
]);
$table->addColumn('exposure_policy', Types::STRING, [
'length' => 32,
'default' => 'private',
]);
$table->addColumn('sort_order', Types::INTEGER, [
'default' => 0,
'unsigned' => true,
]);
$table->addColumn('active', Types::BOOLEAN, [
'default' => true,
]);
$table->addColumn('options', Types::TEXT, [
'notnull' => false,
'default' => null,
]);
$table->addColumn('created_at', Types::DATETIME, []);
$table->addColumn('updated_at', Types::DATETIME, []);
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['field_key'], 'profile_fields_def_key_uk');
$table->addIndex(['active', 'sort_order'], 'profile_fields_def_active_order_idx');
}
if (!$schema->hasTable('profile_fields_values')) {
$table = $schema->createTable('profile_fields_values');
$table->addColumn('id', Types::BIGINT, [
'autoincrement' => true,
'unsigned' => true,
]);
$table->addColumn('field_definition_id', Types::BIGINT, [
'unsigned' => true,
]);
$table->addColumn('user_uid', Types::STRING, [
'length' => 64,
]);
$table->addColumn('value_json', Types::TEXT, []);
$table->addColumn('current_visibility', Types::STRING, [
'length' => 32,
'default' => 'private',
]);
$table->addColumn('updated_by_uid', Types::STRING, [
'length' => 64,
]);
$table->addColumn('updated_at', Types::DATETIME, []);
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['field_definition_id', 'user_uid'], 'profile_fields_val_field_user_uk');
$table->addIndex(['user_uid'], 'profile_fields_val_user_idx');
$table->addIndex(['field_definition_id'], 'profile_fields_val_field_idx');
$table->addForeignKeyConstraint(
$schema->getTable('profile_fields_definitions'),
['field_definition_id'],
['id'],
['onDelete' => 'CASCADE'],
'profile_fields_val_field_fk'
);
}
return $schema;
}
}