Skip to content

Commit 24fe3ee

Browse files
authored
Merge pull request #24653 from nextcloud/backport/23044/stable20
[stable20] Handle owncloud migration to latest release
2 parents 209d4c0 + be0936d commit 24fe3ee

26 files changed

+1551
-8
lines changed

apps/dav/appinfo/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<name>WebDAV</name>
66
<summary>WebDAV endpoint</summary>
77
<description>WebDAV endpoint</description>
8-
<version>1.16.1</version>
8+
<version>1.16.2</version>
99
<licence>agpl</licence>
1010
<author>owncloud.org</author>
1111
<namespace>DAV</namespace>

apps/dav/lib/Migration/Version1004Date20170825134824.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
251251
]);
252252
$table->setPrimaryKey(['id']);
253253
$table->addUniqueIndex(['principaluri', 'uri'], 'calendars_index');
254+
} else {
255+
$table = $schema->getTable('calendars');
256+
$table->changeColumn('components', [
257+
'notnull' => false,
258+
'length' => 64,
259+
]);
254260
}
255261

256262
if (!$schema->hasTable('calendarchanges')) {
@@ -335,6 +341,12 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
335341
]);
336342
$table->setPrimaryKey(['id']);
337343
$table->addUniqueIndex(['principaluri', 'uri'], 'calsub_index');
344+
} else {
345+
$table = $schema->getTable('calendarsubscriptions');
346+
$table->changeColumn('lastmodified', [
347+
'notnull' => false,
348+
'unsigned' => true,
349+
]);
338350
}
339351

340352
if (!$schema->hasTable('schedulingobjects')) {

apps/files_external/lib/Migration/Version1011Date20200630192246.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
121121
$table->setPrimaryKey(['config_id']);
122122
$table->addIndex(['mount_id'], 'config_mount');
123123
$table->addUniqueIndex(['mount_id', 'key'], 'config_mount_key');
124+
} else {
125+
$table = $schema->getTable('external_config');
126+
$table->changeColumn('value', [
127+
'notnull' => false,
128+
'length' => 4096,
129+
]);
124130
}
125131

126132
if (!$schema->hasTable('external_options')) {

core/Application.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ function (GenericEvent $event) use ($container) {
144144
if (!$table->hasIndex('cards_abid')) {
145145
$subject->addHintForMissingSubject($table->getName(), 'cards_abid');
146146
}
147+
148+
if (!$table->hasIndex('cards_abiduri')) {
149+
$subject->addHintForMissingSubject($table->getName(), 'cards_abiduri');
150+
}
147151
}
148152

149153
if ($schema->hasTable('cards_properties')) {

core/Command/Db/AddMissingIndices.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,23 @@ private function addCoreIndexes(OutputInterface $output) {
193193
}
194194

195195
$output->writeln('<info>Check indices of the cards table.</info>');
196+
$cardsUpdated = false;
196197
if ($schema->hasTable('cards')) {
197198
$table = $schema->getTable('cards');
199+
200+
if ($table->hasIndex('addressbookid_uri_index')) {
201+
$output->writeln('<info>Renaming addressbookid_uri_index index to to the cards table, this can take some time...</info>');
202+
203+
foreach ($table->getIndexes() as $index) {
204+
if ($index->getColumns() === ['addressbookid', 'uri']) {
205+
$table->renameIndex('addressbookid_uri_index', 'cards_abiduri');
206+
}
207+
}
208+
209+
$this->connection->migrateToSchema($schema->getWrappedSchema());
210+
$cardsUpdated = true;
211+
}
212+
198213
if (!$table->hasIndex('cards_abid')) {
199214
$output->writeln('<info>Adding cards_abid index to the cards table, this can take some time...</info>');
200215

@@ -206,6 +221,24 @@ private function addCoreIndexes(OutputInterface $output) {
206221

207222
$table->addIndex(['addressbookid'], 'cards_abid');
208223
$this->connection->migrateToSchema($schema->getWrappedSchema());
224+
$cardsUpdated = true;
225+
}
226+
227+
if (!$table->hasIndex('cards_abiduri')) {
228+
$output->writeln('<info>Adding cards_abiduri index to the cards table, this can take some time...</info>');
229+
230+
foreach ($table->getIndexes() as $index) {
231+
if ($index->getColumns() === ['addressbookid', 'uri']) {
232+
$table->dropIndex($index->getName());
233+
}
234+
}
235+
236+
$table->addIndex(['addressbookid', 'uri'], 'cards_abiduri');
237+
$this->connection->migrateToSchema($schema->getWrappedSchema());
238+
$cardsUpdated = true;
239+
}
240+
241+
if ($cardsUpdated) {
209242
$updated = true;
210243
$output->writeln('<info>cards table updated successfully.</info>');
211244
}

core/Migrations/Version13000Date20170718121200.php

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,37 @@
3131

3232
use Doctrine\DBAL\Types\Types;
3333
use OCP\DB\ISchemaWrapper;
34+
use OCP\IDBConnection;
3435
use OCP\Migration\IOutput;
3536
use OCP\Migration\SimpleMigrationStep;
3637

3738
class Version13000Date20170718121200 extends SimpleMigrationStep {
3839

40+
/** @var IDBConnection */
41+
private $connection;
42+
43+
public function __construct(IDBConnection $connection) {
44+
$this->connection = $connection;
45+
}
46+
47+
public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
48+
/** @var ISchemaWrapper $schema */
49+
$schema = $schemaClosure();
50+
51+
if (!$schema->hasTable('properties')) {
52+
return;
53+
}
54+
// in case we have a properties table from oc we drop it since we will only migrate
55+
// the dav_properties values in the postSchemaChange step
56+
$table = $schema->getTable('properties');
57+
if ($table->hasColumn('fileid')) {
58+
$qb = $this->connection->getQueryBuilder();
59+
$qb->delete('properties');
60+
$qb->execute();
61+
}
62+
}
63+
64+
3965
/**
4066
* @param IOutput $output
4167
* @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
@@ -122,6 +148,15 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
122148
$table->addIndex(['root_id'], 'mounts_root_index');
123149
$table->addIndex(['mount_id'], 'mounts_mount_id_index');
124150
$table->addUniqueIndex(['user_id', 'root_id'], 'mounts_user_root_index');
151+
} else {
152+
$table = $schema->getTable('mounts');
153+
$table->addColumn('mount_id', Types::BIGINT, [
154+
'notnull' => false,
155+
'length' => 20,
156+
]);
157+
if (!$table->hasIndex('mounts_mount_id_index')) {
158+
$table->addIndex(['mount_id'], 'mounts_mount_id_index');
159+
}
125160
}
126161

127162
if (!$schema->hasTable('mimetypes')) {
@@ -320,6 +355,27 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
320355
$table->setPrimaryKey(['id']);
321356
$table->addIndex(['userid'], 'property_index');
322357
$table->addIndex(['userid', 'propertypath'], 'properties_path_index');
358+
} else {
359+
$table = $schema->getTable('properties');
360+
if ($table->hasColumn('propertytype')) {
361+
$table->dropColumn('propertytype');
362+
}
363+
if ($table->hasColumn('fileid')) {
364+
$table->dropColumn('fileid');
365+
}
366+
if (!$table->hasColumn('propertypath')) {
367+
$table->addColumn('propertypath', 'string', [
368+
'notnull' => true,
369+
'length' => 255,
370+
]);
371+
}
372+
if (!$table->hasColumn('userid')) {
373+
$table->addColumn('userid', 'string', [
374+
'notnull' => false,
375+
'length' => 64,
376+
'default' => '',
377+
]);
378+
}
323379
}
324380

325381
if (!$schema->hasTable('share')) {
@@ -415,6 +471,14 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
415471
$table->addIndex(['parent'], 'parent_index');
416472
$table->addIndex(['uid_owner'], 'owner_index');
417473
$table->addIndex(['uid_initiator'], 'initiator_index');
474+
} else {
475+
$table = $schema->getTable('share');
476+
if (!$table->hasColumn('password')) {
477+
$table->addColumn('password', 'string', [
478+
'notnull' => false,
479+
'length' => 255,
480+
]);
481+
}
418482
}
419483

420484
if (!$schema->hasTable('jobs')) {
@@ -505,25 +569,25 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
505569
'default' => '',
506570
]);
507571
$table->addColumn('type', 'smallint', [
508-
'notnull' => true,
572+
'notnull' => false,
509573
'length' => 2,
510574
'default' => 0,
511575
'unsigned' => true,
512576
]);
513577
$table->addColumn('remember', 'smallint', [
514-
'notnull' => true,
578+
'notnull' => false,
515579
'length' => 1,
516580
'default' => 0,
517581
'unsigned' => true,
518582
]);
519583
$table->addColumn('last_activity', 'integer', [
520-
'notnull' => true,
584+
'notnull' => false,
521585
'length' => 4,
522586
'default' => 0,
523587
'unsigned' => true,
524588
]);
525589
$table->addColumn('last_check', 'integer', [
526-
'notnull' => true,
590+
'notnull' => false,
527591
'length' => 4,
528592
'default' => 0,
529593
'unsigned' => true,
@@ -534,6 +598,11 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
534598
$table->setPrimaryKey(['id']);
535599
$table->addUniqueIndex(['token'], 'authtoken_token_index');
536600
$table->addIndex(['last_activity'], 'authtoken_last_activity_idx');
601+
} else {
602+
$table = $schema->getTable('authtoken');
603+
$table->addColumn('scope', 'text', [
604+
'notnull' => false,
605+
]);
537606
}
538607

539608
if (!$schema->hasTable('bruteforce_attempts')) {
@@ -936,4 +1005,32 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
9361005
}
9371006
return $schema;
9381007
}
1008+
1009+
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
1010+
/** @var ISchemaWrapper $schema */
1011+
$schema = $schemaClosure();
1012+
if (!$schema->hasTable('dav_properties')) {
1013+
return;
1014+
}
1015+
$query = $this->connection->getQueryBuilder();
1016+
$query->select('*')
1017+
->from('dav_properties');
1018+
1019+
$insert = $this->connection->getQueryBuilder();
1020+
$insert->insert('properties')
1021+
->setValue('propertypath', $insert->createParameter('propertypath'))
1022+
->setValue('propertyname', $insert->createParameter('propertyname'))
1023+
->setValue('propertyvalue', $insert->createParameter('propertyvalue'))
1024+
->setValue('userid', $insert->createParameter('userid'));
1025+
1026+
$result = $query->execute();
1027+
while ($row = $result->fetch()) {
1028+
preg_match('/(calendar)\/([A-z0-9-@_]+)\//', $row['propertypath'], $match);
1029+
$insert->setParameter('propertypath', (string) $row['propertypath'])
1030+
->setParameter('propertyname', (string) $row['propertyname'])
1031+
->setParameter('propertyvalue', (string) $row['propertyvalue'])
1032+
->setParameter('userid', (string) ($match[2] ?? ''));
1033+
$insert->execute();
1034+
}
1035+
}
9391036
}

core/Migrations/Version13000Date20170919121250.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,17 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
6363
$column->setUnsigned(true);
6464
$column = $table->getColumn('type');
6565
$column->setUnsigned(true);
66-
$column = $table->getColumn('remember');
67-
$column->setUnsigned(true);
66+
if ($table->hasColumn('remember')) {
67+
$column = $table->getColumn('remember');
68+
$column->setUnsigned(true);
69+
} else {
70+
$table->addColumn('remember', 'smallint', [
71+
'notnull' => false,
72+
'length' => 1,
73+
'default' => 0,
74+
'unsigned' => true,
75+
]);
76+
}
6877
$column = $table->getColumn('last_activity');
6978
$column->setUnsigned(true);
7079
$column = $table->getColumn('last_check');
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OC\Core\Migrations;
6+
7+
use Closure;
8+
use OCP\DB\ISchemaWrapper;
9+
use OCP\Migration\IOutput;
10+
use OCP\Migration\SimpleMigrationStep;
11+
12+
class Version21000Date20201120141228 extends SimpleMigrationStep {
13+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
14+
/** @var ISchemaWrapper $schema */
15+
$schema = $schemaClosure();
16+
17+
if ($schema->hasTable('authtoken')) {
18+
$table = $schema->getTable('authtoken');
19+
$loginNameColumn = $table->getColumn('login_name');
20+
if ($loginNameColumn->getLength() !== 255) {
21+
$loginNameColumn->setLength(255);
22+
}
23+
$table->changeColumn('type', [
24+
'notnull' => false,
25+
]);
26+
$table->changeColumn('remember', [
27+
'notnull' => false,
28+
]);
29+
$table->changeColumn('last_activity', [
30+
'notnull' => false,
31+
]);
32+
$table->changeColumn('last_check', [
33+
'notnull' => false,
34+
]);
35+
}
36+
37+
if ($schema->hasTable('dav_job_status')) {
38+
$schema->dropTable('dav_job_status');
39+
}
40+
41+
if ($schema->hasTable('systemtag')) {
42+
$table = $schema->getTable('systemtag');
43+
if ($table->hasColumn('systemtag')) {
44+
$table->dropColumn('assignable');
45+
}
46+
}
47+
48+
if ($schema->hasTable('share')) {
49+
$table = $schema->getTable('share');
50+
if ($table->hasColumn('attributes')) {
51+
$table->dropColumn('attributes');
52+
}
53+
}
54+
55+
if ($schema->hasTable('jobs')) {
56+
$table = $schema->getTable('jobs');
57+
$table->changeColumn('execution_duration', [
58+
'notnull' => false,
59+
'default' => 0,
60+
]);
61+
}
62+
63+
return $schema;
64+
}
65+
}

lib/composer/composer/autoload_classmap.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,7 @@
924924
'OC\\Core\\Migrations\\Version20000Date20201109081918' => $baseDir . '/core/Migrations/Version20000Date20201109081918.php',
925925
'OC\\Core\\Migrations\\Version20000Date20201109081919' => $baseDir . '/core/Migrations/Version20000Date20201109081919.php',
926926
'OC\\Core\\Migrations\\Version20000Date20201111081915' => $baseDir . '/core/Migrations/Version20000Date20201111081915.php',
927+
'OC\\Core\\Migrations\\Version21000Date20201120141228' => $baseDir . '/core/Migrations/Version21000Date20201120141228.php',
927928
'OC\\Core\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php',
928929
'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php',
929930
'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php',
@@ -1261,8 +1262,14 @@
12611262
'OC\\Repair\\NC20\\EncryptionMigration' => $baseDir . '/lib/private/Repair/NC20/EncryptionMigration.php',
12621263
'OC\\Repair\\NC20\\ShippedDashboardEnable' => $baseDir . '/lib/private/Repair/NC20/ShippedDashboardEnable.php',
12631264
'OC\\Repair\\OldGroupMembershipShares' => $baseDir . '/lib/private/Repair/OldGroupMembershipShares.php',
1265+
'OC\\Repair\\Owncloud\\CleanPreviews' => $baseDir . '/lib/private/Repair/Owncloud/CleanPreviews.php',
1266+
'OC\\Repair\\Owncloud\\CleanPreviewsBackgroundJob' => $baseDir . '/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php',
12641267
'OC\\Repair\\Owncloud\\DropAccountTermsTable' => $baseDir . '/lib/private/Repair/Owncloud/DropAccountTermsTable.php',
1268+
'OC\\Repair\\Owncloud\\InstallCoreBundle' => $baseDir . '/lib/private/Repair/Owncloud/InstallCoreBundle.php',
1269+
'OC\\Repair\\Owncloud\\MoveAvatars' => $baseDir . '/lib/private/Repair/Owncloud/MoveAvatars.php',
1270+
'OC\\Repair\\Owncloud\\MoveAvatarsBackgroundJob' => $baseDir . '/lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php',
12651271
'OC\\Repair\\Owncloud\\SaveAccountsTableData' => $baseDir . '/lib/private/Repair/Owncloud/SaveAccountsTableData.php',
1272+
'OC\\Repair\\Owncloud\\UpdateLanguageCodes' => $baseDir . '/lib/private/Repair/Owncloud/UpdateLanguageCodes.php',
12661273
'OC\\Repair\\RemoveLinkShares' => $baseDir . '/lib/private/Repair/RemoveLinkShares.php',
12671274
'OC\\Repair\\RepairInvalidShares' => $baseDir . '/lib/private/Repair/RepairInvalidShares.php',
12681275
'OC\\Repair\\RepairMimeTypes' => $baseDir . '/lib/private/Repair/RepairMimeTypes.php',

0 commit comments

Comments
 (0)