Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle owncloud migration to latest release #23044

Merged
merged 21 commits into from
Dec 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
9c2e9f2
Add missing table columns
juliusknorr Sep 25, 2020
96071d7
Allow upgrade from oc 10.5
juliusknorr Sep 25, 2020
7518f67
Drop fk constraints on locks table
juliusknorr Sep 25, 2020
83f4f48
Fix missing authtoken scope
juliusknorr Sep 25, 2020
f5501ca
Avoid checking for brute force protection capabilities when upgrading
juliusknorr Sep 25, 2020
2607ac3
Allow major/minor match for owncloud version
juliusknorr Sep 25, 2020
b983639
Adjust calendars.components to 64 chars
PVince81 Oct 29, 2020
0d42d99
Adjust further columns
PVince81 Oct 29, 2020
ab43d6a
Adjust execution duration to 0
PVince81 Oct 29, 2020
de67719
Drop oc_dav_job_status table
juliusknorr Nov 20, 2020
f276ccb
Drop assignable systemtag column
juliusknorr Nov 20, 2020
fe80a65
Drop attributes on oc_share table
juliusknorr Nov 20, 2020
76addfa
Add missing mount_id index
juliusknorr Nov 27, 2020
3c9218a
Move authtoken login_name column to varchar(255)
juliusknorr Nov 27, 2020
c77e259
Add missing index on oc_cards and rename if it previously existed
juliusknorr Nov 27, 2020
28491ad
Handle oc_dav_properties migration
juliusknorr Dec 7, 2020
9fe94f2
Readd repair steps that are relevant when migrating from ownCloud
juliusknorr Dec 7, 2020
4ef148a
Dump autoloader
juliusknorr Dec 7, 2020
20949d7
Properly migrate from new owncloud avatar location
juliusknorr Dec 9, 2020
0befe07
Change further columns to be nullable with a default of 0
juliusknorr Dec 9, 2020
36ffad5
Make sure the migrations table schema is always checked
juliusknorr Dec 9, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apps/dav/lib/Migration/Version1004Date20170825134824.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
]);
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['principaluri', 'uri'], 'calendars_index');
} else {
$table = $schema->getTable('calendars');
$table->changeColumn('components', [
'notnull' => false,
'length' => 64,
]);
}

if (!$schema->hasTable('calendarchanges')) {
Expand Down Expand Up @@ -335,6 +341,12 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
]);
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['principaluri', 'uri'], 'calsub_index');
} else {
$table = $schema->getTable('calendarsubscriptions');
$table->changeColumn('lastmodified', [
'notnull' => false,
'unsigned' => true,
]);
}

if (!$schema->hasTable('schedulingobjects')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$table->setPrimaryKey(['config_id']);
$table->addIndex(['mount_id'], 'config_mount');
$table->addUniqueIndex(['mount_id', 'key'], 'config_mount_key');
} else {
$table = $schema->getTable('external_config');
$table->changeColumn('value', [
'notnull' => false,
'length' => 4096,
]);
}

if (!$schema->hasTable('external_options')) {
Expand Down
4 changes: 4 additions & 0 deletions core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ function (GenericEvent $event) use ($container) {
if (!$table->hasIndex('cards_abid')) {
$subject->addHintForMissingSubject($table->getName(), 'cards_abid');
}

if (!$table->hasIndex('cards_abiduri')) {
$subject->addHintForMissingSubject($table->getName(), 'cards_abiduri');
}
}

if ($schema->hasTable('cards_properties')) {
Expand Down
33 changes: 33 additions & 0 deletions core/Command/Db/AddMissingIndices.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,23 @@ private function addCoreIndexes(OutputInterface $output) {
}

$output->writeln('<info>Check indices of the cards table.</info>');
$cardsUpdated = false;
if ($schema->hasTable('cards')) {
$table = $schema->getTable('cards');

if ($table->hasIndex('addressbookid_uri_index')) {
$output->writeln('<info>Renaming addressbookid_uri_index index to to the cards table, this can take some time...</info>');

foreach ($table->getIndexes() as $index) {
if ($index->getColumns() === ['addressbookid', 'uri']) {
$table->renameIndex('addressbookid_uri_index', 'cards_abiduri');
}
}

$this->connection->migrateToSchema($schema->getWrappedSchema());
$cardsUpdated = true;
}

if (!$table->hasIndex('cards_abid')) {
$output->writeln('<info>Adding cards_abid index to the cards table, this can take some time...</info>');

Expand All @@ -213,6 +228,24 @@ private function addCoreIndexes(OutputInterface $output) {

$table->addIndex(['addressbookid'], 'cards_abid');
$this->connection->migrateToSchema($schema->getWrappedSchema());
$cardsUpdated = true;
}

if (!$table->hasIndex('cards_abiduri')) {
$output->writeln('<info>Adding cards_abiduri index to the cards table, this can take some time...</info>');

foreach ($table->getIndexes() as $index) {
if ($index->getColumns() === ['addressbookid', 'uri']) {
$table->dropIndex($index->getName());
}
}

$table->addIndex(['addressbookid', 'uri'], 'cards_abiduri');
$this->connection->migrateToSchema($schema->getWrappedSchema());
$cardsUpdated = true;
}

if ($cardsUpdated) {
$updated = true;
$output->writeln('<info>cards table updated successfully.</info>');
}
Expand Down
105 changes: 101 additions & 4 deletions core/Migrations/Version13000Date20170718121200.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,37 @@

use Doctrine\DBAL\Types\Types;
use OCP\DB\ISchemaWrapper;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version13000Date20170718121200 extends SimpleMigrationStep {

/** @var IDBConnection */
private $connection;

public function __construct(IDBConnection $connection) {
$this->connection = $connection;
}

public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

if (!$schema->hasTable('properties')) {
return;
}
// in case we have a properties table from oc we drop it since we will only migrate
// the dav_properties values in the postSchemaChange step
$table = $schema->getTable('properties');
if ($table->hasColumn('fileid')) {
$qb = $this->connection->getQueryBuilder();
$qb->delete('properties');
$qb->execute();
}
}


/**
* @param IOutput $output
* @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
Expand Down Expand Up @@ -122,6 +148,15 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
$table->addIndex(['root_id'], 'mounts_root_index');
$table->addIndex(['mount_id'], 'mounts_mount_id_index');
$table->addUniqueIndex(['user_id', 'root_id'], 'mounts_user_root_index');
} else {
$table = $schema->getTable('mounts');
$table->addColumn('mount_id', Types::BIGINT, [
'notnull' => false,
'length' => 20,
]);
if (!$table->hasIndex('mounts_mount_id_index')) {
$table->addIndex(['mount_id'], 'mounts_mount_id_index');
}
}

if (!$schema->hasTable('mimetypes')) {
Expand Down Expand Up @@ -321,6 +356,27 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
$table->setPrimaryKey(['id']);
$table->addIndex(['userid'], 'property_index');
$table->addIndex(['userid', 'propertypath'], 'properties_path_index');
} else {
$table = $schema->getTable('properties');
if ($table->hasColumn('propertytype')) {
$table->dropColumn('propertytype');
}
if ($table->hasColumn('fileid')) {
$table->dropColumn('fileid');
}
if (!$table->hasColumn('propertypath')) {
$table->addColumn('propertypath', 'string', [
'notnull' => true,
'length' => 255,
]);
}
if (!$table->hasColumn('userid')) {
$table->addColumn('userid', 'string', [
'notnull' => false,
'length' => 64,
'default' => '',
]);
}
}

if (!$schema->hasTable('share')) {
Expand Down Expand Up @@ -416,6 +472,14 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
$table->addIndex(['parent'], 'parent_index');
$table->addIndex(['uid_owner'], 'owner_index');
$table->addIndex(['uid_initiator'], 'initiator_index');
} else {
$table = $schema->getTable('share');
if (!$table->hasColumn('password')) {
$table->addColumn('password', 'string', [
'notnull' => false,
'length' => 255,
]);
}
}

if (!$schema->hasTable('jobs')) {
Expand Down Expand Up @@ -506,25 +570,25 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
'default' => '',
]);
$table->addColumn('type', 'smallint', [
'notnull' => true,
'notnull' => false,
'length' => 2,
'default' => 0,
'unsigned' => true,
]);
$table->addColumn('remember', 'smallint', [
'notnull' => true,
'notnull' => false,
'length' => 1,
'default' => 0,
'unsigned' => true,
]);
$table->addColumn('last_activity', 'integer', [
'notnull' => true,
'notnull' => false,
'length' => 4,
'default' => 0,
'unsigned' => true,
]);
$table->addColumn('last_check', 'integer', [
'notnull' => true,
'notnull' => false,
'length' => 4,
'default' => 0,
'unsigned' => true,
Expand All @@ -535,6 +599,11 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
$table->setPrimaryKey(['id']);
$table->addUniqueIndex(['token'], 'authtoken_token_index');
$table->addIndex(['last_activity'], 'authtoken_last_activity_idx');
} else {
$table = $schema->getTable('authtoken');
$table->addColumn('scope', 'text', [
'notnull' => false,
]);
}

if (!$schema->hasTable('bruteforce_attempts')) {
Expand Down Expand Up @@ -937,4 +1006,32 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
}
return $schema;
}

public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();
if (!$schema->hasTable('dav_properties')) {
return;
}
$query = $this->connection->getQueryBuilder();
$query->select('*')
->from('dav_properties');

$insert = $this->connection->getQueryBuilder();
$insert->insert('properties')
->setValue('propertypath', $insert->createParameter('propertypath'))
->setValue('propertyname', $insert->createParameter('propertyname'))
->setValue('propertyvalue', $insert->createParameter('propertyvalue'))
->setValue('userid', $insert->createParameter('userid'));

$result = $query->execute();
while ($row = $result->fetch()) {
preg_match('/(calendar)\/([A-z0-9-@_]+)\//', $row['propertypath'], $match);
$insert->setParameter('propertypath', (string) $row['propertypath'])
->setParameter('propertyname', (string) $row['propertyname'])
->setParameter('propertyvalue', (string) $row['propertyvalue'])
->setParameter('userid', (string) ($match[2] ?? ''));
$insert->execute();
}
}
}
13 changes: 11 additions & 2 deletions core/Migrations/Version13000Date20170919121250.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,17 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op
$column->setUnsigned(true);
$column = $table->getColumn('type');
$column->setUnsigned(true);
$column = $table->getColumn('remember');
$column->setUnsigned(true);
if ($table->hasColumn('remember')) {
$column = $table->getColumn('remember');
$column->setUnsigned(true);
} else {
$table->addColumn('remember', 'smallint', [
'notnull' => false,
'length' => 1,
'default' => 0,
'unsigned' => true,
]);
}
$column = $table->getColumn('last_activity');
$column->setUnsigned(true);
$column = $table->getColumn('last_check');
Expand Down
65 changes: 65 additions & 0 deletions core/Migrations/Version21000Date20201120141228.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types=1);

namespace OC\Core\Migrations;

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version21000Date20201120141228 extends SimpleMigrationStep {
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

if ($schema->hasTable('authtoken')) {
$table = $schema->getTable('authtoken');
$loginNameColumn = $table->getColumn('login_name');
if ($loginNameColumn->getLength() !== 255) {
$loginNameColumn->setLength(255);
}
$table->changeColumn('type', [
'notnull' => false,
]);
$table->changeColumn('remember', [
'notnull' => false,
]);
$table->changeColumn('last_activity', [
'notnull' => false,
]);
$table->changeColumn('last_check', [
'notnull' => false,
]);
}

if ($schema->hasTable('dav_job_status')) {
$schema->dropTable('dav_job_status');
}

if ($schema->hasTable('systemtag')) {
$table = $schema->getTable('systemtag');
if ($table->hasColumn('systemtag')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong check, this should be "hasColumn('assignable')"

$table->dropColumn('assignable');
}
}

if ($schema->hasTable('share')) {
$table = $schema->getTable('share');
if ($table->hasColumn('attributes')) {
$table->dropColumn('attributes');
}
}

if ($schema->hasTable('jobs')) {
$table = $schema->getTable('jobs');
$table->changeColumn('execution_duration', [
'notnull' => false,
'default' => 0,
]);
}

return $schema;
}
}
7 changes: 7 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,7 @@
'OC\\Core\\Migrations\\Version20000Date20201109081918' => $baseDir . '/core/Migrations/Version20000Date20201109081918.php',
'OC\\Core\\Migrations\\Version20000Date20201109081919' => $baseDir . '/core/Migrations/Version20000Date20201109081919.php',
'OC\\Core\\Migrations\\Version20000Date20201111081915' => $baseDir . '/core/Migrations/Version20000Date20201111081915.php',
'OC\\Core\\Migrations\\Version21000Date20201120141228' => $baseDir . '/core/Migrations/Version21000Date20201120141228.php',
'OC\\Core\\Migrations\\Version21000Date20201202095923' => $baseDir . '/core/Migrations/Version21000Date20201202095923.php',
'OC\\Core\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php',
'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php',
Expand Down Expand Up @@ -1269,8 +1270,14 @@
'OC\\Repair\\NC21\\AddCheckForUserCertificatesJob' => $baseDir . '/lib/private/Repair/NC21/AddCheckForUserCertificatesJob.php',
'OC\\Repair\\NC21\\ValidatePhoneNumber' => $baseDir . '/lib/private/Repair/NC21/ValidatePhoneNumber.php',
'OC\\Repair\\OldGroupMembershipShares' => $baseDir . '/lib/private/Repair/OldGroupMembershipShares.php',
'OC\\Repair\\Owncloud\\CleanPreviews' => $baseDir . '/lib/private/Repair/Owncloud/CleanPreviews.php',
'OC\\Repair\\Owncloud\\CleanPreviewsBackgroundJob' => $baseDir . '/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php',
'OC\\Repair\\Owncloud\\DropAccountTermsTable' => $baseDir . '/lib/private/Repair/Owncloud/DropAccountTermsTable.php',
'OC\\Repair\\Owncloud\\InstallCoreBundle' => $baseDir . '/lib/private/Repair/Owncloud/InstallCoreBundle.php',
'OC\\Repair\\Owncloud\\MoveAvatars' => $baseDir . '/lib/private/Repair/Owncloud/MoveAvatars.php',
'OC\\Repair\\Owncloud\\MoveAvatarsBackgroundJob' => $baseDir . '/lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php',
'OC\\Repair\\Owncloud\\SaveAccountsTableData' => $baseDir . '/lib/private/Repair/Owncloud/SaveAccountsTableData.php',
'OC\\Repair\\Owncloud\\UpdateLanguageCodes' => $baseDir . '/lib/private/Repair/Owncloud/UpdateLanguageCodes.php',
'OC\\Repair\\RemoveLinkShares' => $baseDir . '/lib/private/Repair/RemoveLinkShares.php',
'OC\\Repair\\RepairInvalidShares' => $baseDir . '/lib/private/Repair/RepairInvalidShares.php',
'OC\\Repair\\RepairMimeTypes' => $baseDir . '/lib/private/Repair/RepairMimeTypes.php',
Expand Down
Loading