Skip to content

Commit 741e140

Browse files
Merge pull request #2593 from nextcloud/bugfix/2592/fix-migration-for-mysql
fix(migration): Fix migration for MySQL which does not allow joining
2 parents 40488da + 567d13b commit 741e140

File tree

8 files changed

+322
-138
lines changed

8 files changed

+322
-138
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ cypress/videos
2424
cypress/snapshots
2525
cypress/downloads
2626

27-
js/*hot-update.*
27+
js/*hot-update.*
28+
tests/.phpunit.result.cache

appinfo/info.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<name>Photos</name>
1010
<summary>Your memories under your control</summary>
1111
<description>Your memories under your control</description>
12-
<version>4.0.0</version>
12+
<version>4.0.0-dev.1</version>
1313
<licence>agpl</licence>
1414
<author mail="[email protected]">John Molakvoæ</author>
1515
<namespace>Photos</namespace>
@@ -22,7 +22,6 @@
2222
<website>https://github.com/nextcloud/photos</website>
2323
<bugs>https://github.com/nextcloud/photos/issues</bugs>
2424
<repository>https://github.com/nextcloud/photos.git</repository>
25-
<default_enable />
2625
<dependencies>
2726
<nextcloud min-version="31" max-version="31" />
2827
</dependencies>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"psalm:update-baseline": "psalm.phar --threads=1 --update-baseline",
2626
"psalm:clear": "psalm.phar --clear-cache && psalm --clear-global-cache",
2727
"psalm:fix": "psalm.phar --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType",
28-
"test:unit": "echo 'Only testing installation of the app'"
28+
"test:unit": "vendor/bin/phpunit -c tests/phpunit.xml --color --fail-on-warning --fail-on-risky"
2929
},
3030
"require-dev": {
3131
"bamarni/composer-bin-plugin": "^1.8",

lib/Migration/Version30000Date20240417075404.php renamed to lib/Migration/Version30000Date20240417075405.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111

1212
use Closure;
1313
use OCP\DB\ISchemaWrapper;
14+
use OCP\DB\QueryBuilder\IQueryBuilder;
1415
use OCP\IDBConnection;
1516
use OCP\Migration\IOutput;
1617
use OCP\Migration\SimpleMigrationStep;
1718

1819
/**
1920
* Migrate the photosSourceFolder user config to photosSourceFolders
2021
*/
21-
class Version30000Date20240417075404 extends SimpleMigrationStep {
22+
class Version30000Date20240417075405 extends SimpleMigrationStep {
2223
public function __construct(
2324
private IDBConnection $db,
2425
) {
@@ -36,13 +37,26 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array
3637
->where($select->expr()->eq('appid', $select->expr()->literal('photos')))
3738
->andWhere($select->expr()->eq('configkey', $select->expr()->literal('photosSourceFolders')));
3839

40+
$result = $select->executeQuery();
41+
$alreadyMigrated = array_map(static fn (array $row) => $row['userid'], $result->fetchAll());
42+
$result->closeCursor();
43+
3944
// Remove old entries for users who already have the new one
4045
$delete = $this->db->getQueryBuilder();
4146
$delete->delete('preferences')
4247
->where($delete->expr()->eq('appid', $delete->expr()->literal('photos')))
4348
->andWhere($delete->expr()->eq('configkey', $delete->expr()->literal('photosSourceFolder')))
44-
->andWhere($delete->expr()->in('userid', $delete->createFunction($select->getSQL())))
45-
->executeStatement();
49+
->andWhere($delete->expr()->in(
50+
'userid',
51+
$delete->createParameter('chunk'),
52+
IQueryBuilder::PARAM_STR
53+
));
54+
55+
$chunks = array_chunk($alreadyMigrated, 1000);
56+
foreach ($chunks as $chunk) {
57+
$delete->setParameter('chunk', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
58+
$delete->executeStatement();
59+
}
4660

4761
// Update remaining old entries to new ones
4862
$update = $this->db->getQueryBuilder();

0 commit comments

Comments
 (0)