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

[stable30] fix(migration): Fix migration for MySQL which does not allow joining #2607

Merged
merged 4 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ cypress/videos
cypress/snapshots
cypress/downloads

js/*hot-update.*
js/*hot-update.*
tests/.phpunit.result.cache
3 changes: 1 addition & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<name>Photos</name>
<summary>Your memories under your control</summary>
<description>Your memories under your control</description>
<version>3.0.1</version>
<version>3.0.2</version>
<licence>agpl</licence>
<author mail="[email protected]">John Molakvoæ</author>
<namespace>Photos</namespace>
Expand All @@ -22,7 +22,6 @@
<website>https://github.com/nextcloud/photos</website>
<bugs>https://github.com/nextcloud/photos/issues</bugs>
<repository>https://github.com/nextcloud/photos.git</repository>
<default_enable />
<dependencies>
<nextcloud min-version="30" max-version="30" />
</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"psalm:update-baseline": "psalm.phar --threads=1 --update-baseline",
"psalm:clear": "psalm.phar --clear-cache && psalm --clear-global-cache",
"psalm:fix": "psalm.phar --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType",
"test:unit": "echo 'Only testing installation of the app'"
"test:unit": "vendor/bin/phpunit -c tests/phpunit.xml --color --fail-on-warning --fail-on-risky"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

/**
* Migrate the photosSourceFolder user config to photosSourceFolders
*/
class Version30000Date20240417075404 extends SimpleMigrationStep {
class Version30000Date20240417075405 extends SimpleMigrationStep {
public function __construct(
private IDBConnection $db,
) {
Expand All @@ -36,13 +37,26 @@ public function postSchemaChange(IOutput $output, Closure $schemaClosure, array
->where($select->expr()->eq('appid', $select->expr()->literal('photos')))
->andWhere($select->expr()->eq('configkey', $select->expr()->literal('photosSourceFolders')));

$result = $select->executeQuery();
$alreadyMigrated = array_map(static fn (array $row) => $row['userid'], $result->fetchAll());
$result->closeCursor();

// Remove old entries for users who already have the new one
$delete = $this->db->getQueryBuilder();
$delete->delete('preferences')
->where($delete->expr()->eq('appid', $delete->expr()->literal('photos')))
->andWhere($delete->expr()->eq('configkey', $delete->expr()->literal('photosSourceFolder')))
->andWhere($delete->expr()->in('userid', $delete->createFunction($select->getSQL())))
->executeStatement();
->andWhere($delete->expr()->in(
'userid',
$delete->createParameter('chunk'),
IQueryBuilder::PARAM_STR
));

$chunks = array_chunk($alreadyMigrated, 1000);
foreach ($chunks as $chunk) {
$delete->setParameter('chunk', $chunk, IQueryBuilder::PARAM_STR_ARRAY);
$delete->executeStatement();
}

// Update remaining old entries to new ones
$update = $this->db->getQueryBuilder();
Expand Down
Loading
Loading