Skip to content

Commit c86f2e9

Browse files
committed
feat(migration-attributes): add DataCleansing
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent bc2321d commit c86f2e9

File tree

10 files changed

+58
-12
lines changed

10 files changed

+58
-12
lines changed

core/Migrations/Version32000Date20250620081925.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99

1010
namespace OC\Core\Migrations;
1111

12+
use OCP\Migration\Attributes\DataCleansing;
13+
1214
/**
1315
* Run the old migration Version24000Date20211210141942 again.
1416
*/
17+
#[DataCleansing(table: 'preferences', description: 'lowercase accounts email address')]
1518
class Version32000Date20250620081925 extends Version24000Date20211210141942 {
1619
}

core/Migrations/Version32000Date20250731062008.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Closure;
1313
use OCP\DB\ISchemaWrapper;
1414
use OCP\IDBConnection;
15+
use OCP\Migration\Attributes\DataCleansing;
1516
use OCP\Migration\IOutput;
1617
use OCP\Migration\SimpleMigrationStep;
1718
use Override;
@@ -21,6 +22,8 @@
2122
* This migration will clean up existing duplicates.
2223
* The new unique constraint is added in @see \OC\Core\Listener\AddMissingIndicesListener
2324
*/
25+
#[DataCleansing(table: 'vcategory', description: 'Cleanup of duplicate vcategory records')]
26+
#[DataCleansing(table: 'vcategory_to_object', description: 'Update object references')]
2427
class Version32000Date20250731062008 extends SimpleMigrationStep {
2528
public function __construct(
2629
private IDBConnection $connection,

lib/composer/composer/autoload_classmap.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,8 @@
678678
'OCP\\Migration\\Attributes\\ColumnMigrationAttribute' => $baseDir . '/lib/public/Migration/Attributes/ColumnMigrationAttribute.php',
679679
'OCP\\Migration\\Attributes\\ColumnType' => $baseDir . '/lib/public/Migration/Attributes/ColumnType.php',
680680
'OCP\\Migration\\Attributes\\CreateTable' => $baseDir . '/lib/public/Migration/Attributes/CreateTable.php',
681+
'OCP\\Migration\\Attributes\\DataCleansing' => $baseDir . '/lib/public/Migration/Attributes/DataCleansing.php',
682+
'OCP\\Migration\\Attributes\\DataMigrationAttribute' => $baseDir . '/lib/public/Migration/Attributes/DataMigrationAttribute.php',
681683
'OCP\\Migration\\Attributes\\DropColumn' => $baseDir . '/lib/public/Migration/Attributes/DropColumn.php',
682684
'OCP\\Migration\\Attributes\\DropIndex' => $baseDir . '/lib/public/Migration/Attributes/DropIndex.php',
683685
'OCP\\Migration\\Attributes\\DropTable' => $baseDir . '/lib/public/Migration/Attributes/DropTable.php',

lib/composer/composer/autoload_static.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
719719
'OCP\\Migration\\Attributes\\ColumnMigrationAttribute' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/ColumnMigrationAttribute.php',
720720
'OCP\\Migration\\Attributes\\ColumnType' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/ColumnType.php',
721721
'OCP\\Migration\\Attributes\\CreateTable' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/CreateTable.php',
722+
'OCP\\Migration\\Attributes\\DataCleansing' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/DataCleansing.php',
723+
'OCP\\Migration\\Attributes\\DataMigrationAttribute' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/DataMigrationAttribute.php',
722724
'OCP\\Migration\\Attributes\\DropColumn' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/DropColumn.php',
723725
'OCP\\Migration\\Attributes\\DropIndex' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/DropIndex.php',
724726
'OCP\\Migration\\Attributes\\DropTable' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/DropTable.php',

lib/public/Migration/Attributes/ColumnMigrationAttribute.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
*/
99
namespace OCP\Migration\Attributes;
1010

11-
use JsonSerializable;
12-
1311
/**
1412
* generic class related to migration attribute about column changes
1513
*
1614
* @since 30.0.0
1715
*/
18-
class ColumnMigrationAttribute extends MigrationAttribute implements JsonSerializable {
16+
class ColumnMigrationAttribute extends MigrationAttribute {
1917
/**
2018
* @param string $table name of the database table
2119
* @param string $name name of the column
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
namespace OCP\Migration\Attributes;
10+
11+
use Attribute;
12+
13+
/**
14+
* attribute on new column creation
15+
*
16+
* @since 32.0.0
17+
*/
18+
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
19+
class DataCleansing extends DataMigrationAttribute {
20+
/**
21+
* @return string
22+
* @since 32.0.0
23+
*/
24+
public function definition(): string {
25+
return 'Cleansing data from table \'' . $this->getTable() . '\'';
26+
}
27+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
namespace OCP\Migration\Attributes;
10+
11+
/**
12+
* generic class related to migration attribute about data migration
13+
*
14+
* @since 32.0.0
15+
*/
16+
class DataMigrationAttribute extends MigrationAttribute {
17+
}

lib/public/Migration/Attributes/GenericMigrationAttribute.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,13 @@
88
*/
99
namespace OCP\Migration\Attributes;
1010

11-
use JsonSerializable;
12-
1311
/**
1412
* generic entry, used to replace migration attribute not yet known in current version
1513
* but used in a future release
1614
*
1715
* @since 30.0.0
1816
*/
19-
class GenericMigrationAttribute extends MigrationAttribute implements JsonSerializable {
17+
class GenericMigrationAttribute extends MigrationAttribute {
2018
/**
2119
* @param array $details
2220
* @since 30.0.0

lib/public/Migration/Attributes/IndexMigrationAttribute.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
*/
99
namespace OCP\Migration\Attributes;
1010

11-
use JsonSerializable;
12-
1311
/**
1412
* generic class related to migration attribute about index changes
1513
*
1614
* @since 30.0.0
1715
*/
18-
class IndexMigrationAttribute extends MigrationAttribute implements JsonSerializable {
16+
class IndexMigrationAttribute extends MigrationAttribute {
1917
/**
2018
* @param string $table name of the database table
2119
* @param IndexType|null $type type of the index

lib/public/Migration/Attributes/TableMigrationAttribute.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
*/
99
namespace OCP\Migration\Attributes;
1010

11-
use JsonSerializable;
12-
1311
/**
1412
* generic class related to migration attribute about table changes
1513
*
1614
* @since 30.0.0
1715
*/
18-
class TableMigrationAttribute extends MigrationAttribute implements JsonSerializable {
16+
class TableMigrationAttribute extends MigrationAttribute {
1917
/**
2018
* @param string $table name of the database table
2119
* @param array $columns list of columns

0 commit comments

Comments
 (0)