Skip to content

Commit f2907f1

Browse files
authored
Merge pull request #58282 from nextcloud/carl/refactor-migration
refactor(psalm): Modernize migration doc
2 parents b6d22f3 + f6c839d commit f2907f1

26 files changed

Lines changed: 83 additions & 183 deletions

apps/dav/lib/Migration/Version1025Date20240308063933.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,17 @@
1717
use OCP\IDBConnection;
1818
use OCP\Migration\IOutput;
1919
use OCP\Migration\SimpleMigrationStep;
20+
use Override;
2021

2122
class Version1025Date20240308063933 extends SimpleMigrationStep {
2223

2324
public function __construct(
24-
private IAppConfig $appConfig,
25-
private IDBConnection $db,
25+
private readonly IAppConfig $appConfig,
26+
private readonly IDBConnection $db,
2627
) {
2728
}
2829

29-
/**
30-
* @param IOutput $output
31-
* @param Closure(): ISchemaWrapper $schemaClosure
32-
* @param array $options
33-
* @return null|ISchemaWrapper
34-
*/
30+
#[Override]
3531
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
3632
/** @var ISchemaWrapper $schema */
3733
$schema = $schemaClosure();
@@ -50,6 +46,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
5046
return $schema;
5147
}
5248

49+
#[Override]
5350
public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options): void {
5451
// The threshold is higher than the default of \OCA\DAV\BackgroundJob\PruneOutdatedSyncTokensJob
5552
// but small enough to fit into a cluster transaction size.

apps/dav/lib/Migration/Version1027Date20230504122946.php

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

1212
use Closure;
1313
use OCA\DAV\CardDAV\SyncService;
14-
use OCP\DB\ISchemaWrapper;
1514
use OCP\IConfig;
1615
use OCP\IUserManager;
1716
use OCP\Migration\IOutput;
1817
use OCP\Migration\SimpleMigrationStep;
18+
use Override;
1919
use Psr\Log\LoggerInterface;
2020
use Throwable;
2121

@@ -27,11 +27,8 @@ public function __construct(
2727
private IConfig $config,
2828
) {
2929
}
30-
/**
31-
* @param IOutput $output
32-
* @param Closure(): ISchemaWrapper $schemaClosure
33-
* @param array $options
34-
*/
30+
31+
#[Override]
3532
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
3633
if ($this->userManager->countSeenUsers() > 100 || $this->userManager->countUsersTotal(100) >= 100) {
3734
$this->config->setAppValue('dav', 'needs_system_address_book_sync', 'yes');

apps/dav/lib/Migration/Version1029Date20231004091403.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
use Closure;
1313
use OCP\DB\ISchemaWrapper;
1414
use OCP\DB\Types;
15+
use OCP\Migration\Attributes\CreateTable;
1516
use OCP\Migration\IOutput;
1617
use OCP\Migration\SimpleMigrationStep;
18+
use Override;
1719

20+
#[CreateTable(table: 'dav_absence')]
1821
class Version1029Date20231004091403 extends SimpleMigrationStep {
19-
/**
20-
* @param IOutput $output
21-
* @param Closure(): ISchemaWrapper $schemaClosure
22-
* @param array $options
23-
* @return null|ISchemaWrapper
24-
*/
22+
#[Override]
2523
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
2624
/** @var ISchemaWrapper $schema */
2725
$schema = $schemaClosure();

apps/dav/lib/Migration/Version1030Date20240205103243.php

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

1212
use Closure;
1313
use OCP\DB\ISchemaWrapper;
14+
use OCP\Migration\Attributes\DropIndex;
1415
use OCP\Migration\IOutput;
1516
use OCP\Migration\SimpleMigrationStep;
17+
use Override;
1618

19+
#[DropIndex(table: 'cards')]
1720
class Version1030Date20240205103243 extends SimpleMigrationStep {
18-
19-
/**
20-
* @param IOutput $output
21-
* @param Closure(): ISchemaWrapper $schemaClosure
22-
* @param array $options
23-
* @return null|ISchemaWrapper
24-
*/
21+
#[Override]
2522
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
2623
/** @var ISchemaWrapper $schema */
2724
$schema = $schemaClosure();

apps/dav/lib/Migration/Version1034Date20250605132605.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,12 @@
1717
use OCP\Migration\Attributes\CreateTable;
1818
use OCP\Migration\IOutput;
1919
use OCP\Migration\SimpleMigrationStep;
20+
use Override;
2021

2122
#[AddColumn(table: 'dav_shares', name: 'token', type: ColumnType::STRING)]
2223
#[CreateTable(table: 'calendars_federated', columns: ['id', 'display_name', 'color', 'uri', 'principaluri', 'remote_Url', 'token', 'sync_token', 'last_sync', 'shared_by', 'shared_by_display_name', 'components', 'permissions'], description: 'Supporting Federated Calender')]
2324
class Version1034Date20250605132605 extends SimpleMigrationStep {
24-
/**
25-
* @param IOutput $output
26-
* @param Closure(): ISchemaWrapper $schemaClosure
27-
* @param array $options
28-
* @return null|ISchemaWrapper
29-
*/
25+
#[Override]
3026
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
3127
/** @var ISchemaWrapper $schema */
3228
$schema = $schemaClosure();

apps/dav/lib/Migration/Version1034Date20250813093701.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
namespace OCA\DAV\Migration;
1111

1212
use Closure;
13-
use OCP\DB\ISchemaWrapper;
1413
use OCP\DB\QueryBuilder\IQueryBuilder;
1514
use OCP\IDBConnection;
1615
use OCP\Migration\Attributes\DataCleansing;
@@ -25,11 +24,6 @@ public function __construct(
2524
) {
2625
}
2726

28-
/**
29-
* @param IOutput $output
30-
* @param Closure(): ISchemaWrapper $schemaClosure
31-
* @param array $options
32-
*/
3327
#[Override]
3428
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
3529
$qb = $this->db->getQueryBuilder();

apps/dav/lib/Migration/Version1036Date20251202000000.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
#[ModifyColumn(table: 'calendar_reminders', name: 'uid', type: ColumnType::STRING, description: 'Increase uid length to 512 characters')]
2222
#[ModifyColumn(table: 'calendar_invitations', name: 'uid', type: ColumnType::STRING, description: 'Increase uid length to 512 characters')]
2323
class Version1036Date20251202000000 extends SimpleMigrationStep {
24-
/**
25-
* @param Closure(): ISchemaWrapper $schemaClosure
26-
*/
2724
#[Override]
2825
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
2926
/** @var ISchemaWrapper $schema */

apps/files/lib/Migration/Version2003Date20241021095629.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@
1111

1212
use Closure;
1313
use OCA\Files\Service\ChunkedUploadConfig;
14-
use OCP\DB\ISchemaWrapper;
15-
use OCP\IConfig;
14+
use OCP\IAppConfig;
1615
use OCP\Migration\IOutput;
1716
use OCP\Migration\SimpleMigrationStep;
18-
use OCP\Server;
17+
use Override;
1918

2019
class Version2003Date20241021095629 extends SimpleMigrationStep {
21-
/**
22-
* @param IOutput $output
23-
* @param Closure(): ISchemaWrapper $schemaClosure
24-
* @param array $options
25-
*/
20+
public function __construct(
21+
public readonly IAppConfig $appConfig,
22+
) {
23+
}
24+
25+
#[Override]
2626
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
27-
$maxChunkSize = Server::get(IConfig::class)->getAppValue('files', 'max_chunk_size');
28-
if ($maxChunkSize === '') {
27+
$maxChunkSize = $this->appConfig->getValueInt('files', 'max_chunk_size');
28+
if ($maxChunkSize === 0) {
2929
// Skip if no value was configured before
3030
return;
3131
}
3232

33-
ChunkedUploadConfig::setMaxChunkSize((int)$maxChunkSize);
34-
Server::get(IConfig::class)->deleteAppValue('files', 'max_chunk_size');
33+
ChunkedUploadConfig::setMaxChunkSize($maxChunkSize);
34+
$this->appConfig->deleteKey('files', 'max_chunk_size');
3535
}
3636
}

apps/files_external/lib/Migration/Version1025Date20250228162604.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,20 @@
1111

1212
use Closure;
1313
use OCA\Files_External\Service\GlobalStoragesService;
14-
use OCP\DB\ISchemaWrapper;
15-
use OCP\IAppConfig;
1614
use OCP\Migration\IOutput;
1715
use OCP\Migration\SimpleMigrationStep;
16+
use Override;
1817

1918
/**
2019
* Check for any external storage overwriting the home folder
2120
*/
2221
class Version1025Date20250228162604 extends SimpleMigrationStep {
2322
public function __construct(
2423
private GlobalStoragesService $globalStoragesServices,
25-
private IAppConfig $appConfig,
2624
) {
2725
}
2826

29-
/**
30-
* @param Closure(): ISchemaWrapper $schemaClosure
31-
*/
27+
#[Override]
3228
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
3329
$this->globalStoragesServices->updateOverwriteHomeFolders();
3430
}

apps/files_sharing/lib/Migration/Version31000Date20240821142813.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@
1616
use OCP\Migration\Attributes\ColumnType;
1717
use OCP\Migration\IOutput;
1818
use OCP\Migration\SimpleMigrationStep;
19+
use Override;
1920

2021
#[AddColumn(table: 'share', name: 'reminder_sent', type: ColumnType::BOOLEAN)]
2122
class Version31000Date20240821142813 extends SimpleMigrationStep {
22-
23-
/**
24-
* @param IOutput $output
25-
* @param Closure(): ISchemaWrapper $schemaClosure
26-
* @param array $options
27-
* @return null|ISchemaWrapper
28-
*/
23+
#[Override]
2924
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
25+
/** @var ISchemaWrapper $schema */
3026
$schema = $schemaClosure();
3127
$table = $schema->getTable('share');
3228
if ($table->hasColumn('reminder_sent')) {

0 commit comments

Comments
 (0)