-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
feat(dav): store multiple default calendar alarms as JSON #61832
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
Open
rich0
wants to merge
1
commit into
nextcloud:master
Choose a base branch
from
rich0:upstreampr/pluralcalendardefaults
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\DAV\Migration; | ||
|
|
||
| use Closure; | ||
| use OCP\DB\ISchemaWrapper; | ||
| use OCP\DB\Types; | ||
| use OCP\IDBConnection; | ||
| use OCP\Migration\Attributes\AddColumn; | ||
| use OCP\Migration\Attributes\ColumnType; | ||
| use OCP\Migration\Attributes\DataCleansing; | ||
| use OCP\Migration\IOutput; | ||
| use OCP\Migration\SimpleMigrationStep; | ||
| use Override; | ||
|
|
||
| /** | ||
| * Add JSON default-alarm columns and copy legacy single-int defaults via set-based UPDATEs. | ||
| */ | ||
| #[DataCleansing(table: 'calendars', description: 'Migrate legacy default_alarm_* integers to default_alarms_* JSON')] | ||
| #[AddColumn(table: 'calendars', name: 'default_alarms_pday', type: ColumnType::TEXT)] | ||
| #[AddColumn(table: 'calendars', name: 'default_alarms_fday', type: ColumnType::TEXT)] | ||
| class Version2000Date20260703100001 extends SimpleMigrationStep { | ||
| public function __construct( | ||
| private IDBConnection $db, | ||
| ) { | ||
| } | ||
|
|
||
| #[Override] | ||
| public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
| /** @var ISchemaWrapper $schema */ | ||
| $schema = $schemaClosure(); | ||
|
|
||
| $calendarsTable = $schema->getTable('calendars'); | ||
|
|
||
| if (!$calendarsTable->hasColumn('default_alarms_pday')) { | ||
| $calendarsTable->addColumn('default_alarms_pday', Types::TEXT, [ | ||
| 'notnull' => false, | ||
| 'default' => null, | ||
| ]); | ||
| } | ||
|
|
||
| if (!$calendarsTable->hasColumn('default_alarms_fday')) { | ||
| $calendarsTable->addColumn('default_alarms_fday', Types::TEXT, [ | ||
| 'notnull' => false, | ||
| 'default' => null, | ||
| ]); | ||
| } | ||
|
|
||
| return $schema; | ||
| } | ||
|
|
||
| #[Override] | ||
| public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void { | ||
| /** @var ISchemaWrapper $schema */ | ||
| $schema = $schemaClosure(); | ||
| $calendarsTable = $schema->getTable('calendars'); | ||
|
|
||
| if ($calendarsTable->hasColumn('default_alarm_pday') && $calendarsTable->hasColumn('default_alarms_pday')) { | ||
| $this->migrateLegacyIntColumn('default_alarm_pday', 'default_alarms_pday'); | ||
| } | ||
|
|
||
| if ($calendarsTable->hasColumn('default_alarm_fday') && $calendarsTable->hasColumn('default_alarms_fday')) { | ||
| $this->migrateLegacyIntColumn('default_alarm_fday', 'default_alarms_fday'); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Encode a single legacy trigger int as [{"trigger":N,"action":"DISPLAY"}] | ||
| * for all rows still missing the JSON column value. | ||
| */ | ||
| private function migrateLegacyIntColumn(string $legacyColumn, string $jsonColumn): void { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| $qb = $this->db->getQueryBuilder(); | ||
| $qb->update('calendars') | ||
| ->set($jsonColumn, $qb->func()->concat( | ||
| $qb->expr()->literal('[{"trigger":'), | ||
| $legacyColumn, | ||
| $qb->expr()->literal(',"action":"DISPLAY"}]'), | ||
| )) | ||
| ->where($qb->expr()->isNotNull($legacyColumn)) | ||
| ->andWhere($qb->expr()->isNull($jsonColumn)); | ||
|
Comment on lines
+86
to
+87
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice. It will continue where it left of when interrupted |
||
| $qb->executeStatement(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| namespace OCA\DAV\Migration; | ||
|
|
||
| use Closure; | ||
| use OCP\DB\ISchemaWrapper; | ||
| use OCP\Migration\Attributes\DropColumn; | ||
| use OCP\Migration\IOutput; | ||
| use OCP\Migration\SimpleMigrationStep; | ||
| use Override; | ||
|
|
||
| /** | ||
| * Drop legacy single-int default alarm columns after JSON migration. | ||
| */ | ||
| #[DropColumn(table: 'calendars', name: 'default_alarm_pday', description: 'Replaced by default_alarms_pday JSON')] | ||
| #[DropColumn(table: 'calendars', name: 'default_alarm_fday', description: 'Replaced by default_alarms_fday JSON')] | ||
| class Version2000Date20260703100002 extends SimpleMigrationStep { | ||
| #[Override] | ||
| public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
| /** @var ISchemaWrapper $schema */ | ||
| $schema = $schemaClosure(); | ||
|
|
||
| $calendarsTable = $schema->getTable('calendars'); | ||
|
|
||
| if ($calendarsTable->hasColumn('default_alarm_pday')) { | ||
| $calendarsTable->dropColumn('default_alarm_pday'); | ||
| } | ||
|
|
||
| if ($calendarsTable->hasColumn('default_alarm_fday')) { | ||
| $calendarsTable->dropColumn('default_alarm_fday'); | ||
| } | ||
|
|
||
| return $schema; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need a second migration step to remove the old fields
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was implemented in a separate file - I'm not sure if that is the correct pattern or not.
Also, the migration process was tweaked a bit. I'm not super-familiar with SQL in PHP but I think this will execute as an UPDATE query DB-side which I would hope should perform fairly quickly even on a very large table.