Skip to content

Commit 86dc06c

Browse files
committed
primaryKey on circles_membership
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent d40e8ad commit 86dc06c

File tree

4 files changed

+100
-33
lines changed

4 files changed

+100
-33
lines changed

lib/Migration/Version0023Date20211216113101.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,4 @@ class Version0023Date20211216113101 extends SimpleMigrationStep {
4747
*/
4848
public function __construct(IDBConnection $connection) {
4949
}
50-
5150
}

lib/Migration/Version0024Date20220203123901.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
6969
$table = $schema->getTable('circles_token');
7070
$table->changeColumn(
7171
'password', [
72-
'length' => 127
73-
]
72+
'length' => 127
73+
]
7474
);
7575
}
7676

@@ -105,5 +105,4 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
105105

106106
return $schema;
107107
}
108-
109108
}

lib/Migration/Version0024Date20220203123902.php

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,67 +64,66 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
6464
$table = $schema->createTable('circles_event');
6565
$table->addColumn(
6666
'token', 'string', [
67-
'notnull' => false,
68-
'length' => 63,
69-
]
67+
'notnull' => false,
68+
'length' => 63,
69+
]
7070
);
7171
$table->addColumn(
7272
'event', 'text', [
73-
'notnull' => false
74-
]
73+
'notnull' => false
74+
]
7575
);
7676
$table->addColumn(
7777
'result', 'text', [
78-
'notnull' => false
79-
]
78+
'notnull' => false
79+
]
8080
);
8181
$table->addColumn(
8282
'instance', 'string', [
83-
'length' => 255,
84-
'notnull' => false
85-
]
83+
'length' => 255,
84+
'notnull' => false
85+
]
8686
);
8787
$table->addColumn(
8888
'interface', 'integer', [
89-
'notnull' => true,
90-
'length' => 1,
91-
'default' => 0
92-
]
89+
'notnull' => true,
90+
'length' => 1,
91+
'default' => 0
92+
]
9393
);
9494
$table->addColumn(
9595
'severity', 'integer', [
96-
'length' => 3,
97-
'notnull' => false
98-
]
96+
'length' => 3,
97+
'notnull' => false
98+
]
9999
);
100100
$table->addColumn(
101101
'retry', 'integer', [
102-
'length' => 3,
103-
'notnull' => false
104-
]
102+
'length' => 3,
103+
'notnull' => false
104+
]
105105
);
106106
$table->addColumn(
107107
'status', 'integer', [
108-
'length' => 3,
109-
'notnull' => false
110-
]
108+
'length' => 3,
109+
'notnull' => false
110+
]
111111
);
112112
$table->addColumn(
113113
'updated', 'datetime', [
114-
'notnull' => false,
115-
]
114+
'notnull' => false,
115+
]
116116
);
117117
$table->addColumn(
118118
'creation', 'bigint', [
119-
'length' => 14,
120-
'notnull' => false
121-
]
119+
'length' => 14,
120+
'notnull' => false
121+
]
122122
);
123123

124124
$table->setPrimaryKey(['token', 'instance']);
125125
}
126126

127127
return $schema;
128128
}
129-
130129
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
/**
7+
* Circles - Bring cloud-users closer together.
8+
*
9+
* This file is licensed under the Affero General Public License version 3 or
10+
* later. See the COPYING file.
11+
*
12+
* @author Maxence Lange <maxence@artificial-owl.com>
13+
* @copyright 2022
14+
* @license GNU AGPL version 3 or any later version
15+
*
16+
* This program is free software: you can redistribute it and/or modify
17+
* it under the terms of the GNU Affero General Public License as
18+
* published by the Free Software Foundation, either version 3 of the
19+
* License, or (at your option) any later version.
20+
*
21+
* This program is distributed in the hope that it will be useful,
22+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
* GNU Affero General Public License for more details.
25+
*
26+
* You should have received a copy of the GNU Affero General Public License
27+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
28+
*
29+
*/
30+
31+
32+
namespace OCA\Circles\Migration;
33+
34+
use Closure;
35+
use Doctrine\DBAL\Schema\SchemaException;
36+
use OCP\DB\ISchemaWrapper;
37+
use OCP\Migration\IOutput;
38+
use OCP\Migration\SimpleMigrationStep;
39+
40+
class Version0024Date20220317190331 extends SimpleMigrationStep {
41+
42+
/**
43+
* @param IOutput $output
44+
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
45+
* @param array $options
46+
*
47+
* @return null|ISchemaWrapper
48+
* @throws SchemaException
49+
*/
50+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
51+
/** @var ISchemaWrapper $schema */
52+
$schema = $schemaClosure();
53+
54+
if ($schema->hasTable('circles_membership')) {
55+
$table = $schema->getTable('circles_membership');
56+
if (!$table->hasPrimaryKey()) {
57+
$indexes = $table->getIndexes();
58+
// conflict in Oracle with existing unique index, duplicate of primaryKey.
59+
foreach ($indexes as $index) {
60+
if ($index->isUnique()) {
61+
$table->dropIndex($index->getName());
62+
}
63+
}
64+
$table->setPrimaryKey(['single_id', 'circle_id']);
65+
}
66+
}
67+
68+
return $schema;
69+
}
70+
}

0 commit comments

Comments
 (0)