Skip to content

Commit

Permalink
Migration Attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
  • Loading branch information
ArtificialOwl committed Jul 12, 2024
1 parent 7773f1b commit f7638be
Show file tree
Hide file tree
Showing 14 changed files with 358 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/public/Migration/Attributes/FieldAdd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Migration\Attributes;

use Attribute;

#[Attribute]

Check failure on line 13 in lib/public/Migration/Attributes/FieldAdd.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

InvalidDocblock

lib/public/Migration/Attributes/FieldAdd.php:13:1: InvalidDocblock: PHPDoc is required for classes/interfaces in OCP. (see https://psalm.dev/008)
class FieldAdd extends FieldMigrationAttribute {
}
15 changes: 15 additions & 0 deletions lib/public/Migration/Attributes/FieldChange.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Migration\Attributes;

use Attribute;

#[Attribute]

Check failure on line 13 in lib/public/Migration/Attributes/FieldChange.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

InvalidDocblock

lib/public/Migration/Attributes/FieldChange.php:13:1: InvalidDocblock: PHPDoc is required for classes/interfaces in OCP. (see https://psalm.dev/008)
class FieldChange extends FieldMigrationAttribute {
}
43 changes: 43 additions & 0 deletions lib/public/Migration/Attributes/FieldMigrationAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Migration\Attributes;

use Attribute;
use JsonSerializable;

class FieldMigrationAttribute extends MigrationAttribute implements JsonSerializable {

Check failure on line 14 in lib/public/Migration/Attributes/FieldMigrationAttribute.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

InvalidDocblock

lib/public/Migration/Attributes/FieldMigrationAttribute.php:14:1: InvalidDocblock: PHPDoc is required for classes/interfaces in OCP. (see https://psalm.dev/008)
public function __construct(

Check failure on line 15 in lib/public/Migration/Attributes/FieldMigrationAttribute.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

InvalidDocblock

lib/public/Migration/Attributes/FieldMigrationAttribute.php:15:2: InvalidDocblock: PHPDoc is required for methods in OCP. (see https://psalm.dev/008)
string $table,
private readonly string $field,
private readonly ?FieldType $type = null,
MigrationWeight $weight = MigrationWeight::LIGHT,
string $description = '',
array $notes = [],
) {
parent::__construct($table, $weight, $description, $notes);
}

public function getField(): string {

Check failure on line 26 in lib/public/Migration/Attributes/FieldMigrationAttribute.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

InvalidDocblock

lib/public/Migration/Attributes/FieldMigrationAttribute.php:26:2: InvalidDocblock: PHPDoc is required for methods in OCP. (see https://psalm.dev/008)
return $this->field;
}

public function getType(): ?FieldType {

Check failure on line 30 in lib/public/Migration/Attributes/FieldMigrationAttribute.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

InvalidDocblock

lib/public/Migration/Attributes/FieldMigrationAttribute.php:30:2: InvalidDocblock: PHPDoc is required for methods in OCP. (see https://psalm.dev/008)
return $this->type;
}

public function jsonSerialize(): array {

Check failure on line 34 in lib/public/Migration/Attributes/FieldMigrationAttribute.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

InvalidDocblock

lib/public/Migration/Attributes/FieldMigrationAttribute.php:34:2: InvalidDocblock: PHPDoc is required for methods in OCP. (see https://psalm.dev/008)
return array_merge(
parent::jsonSerialize(),
[
'field' => $this->getField(),
'type' => $this->getType() ?? '',
]
);
}
}
15 changes: 15 additions & 0 deletions lib/public/Migration/Attributes/FieldRemove.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Migration\Attributes;

use Attribute;

#[Attribute]

Check failure on line 13 in lib/public/Migration/Attributes/FieldRemove.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

InvalidDocblock

lib/public/Migration/Attributes/FieldRemove.php:13:1: InvalidDocblock: PHPDoc is required for classes/interfaces in OCP. (see https://psalm.dev/008)
class FieldRemove extends FieldMigrationAttribute {
}
46 changes: 46 additions & 0 deletions lib/public/Migration/Attributes/FieldType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Migration\Attributes;

/**
* enum FieldType based on OCP\DB\Types
*
* @see \OCP\DB\Types
* @since 30.0.0
*/
enum FieldType : string {
/** @since 30.0.0 */
case BIGINT = 'bigint';
/** @since 30.0.0 */
case BINARY = 'binary';
/** @since 30.0.0 */
case BLOB = 'blob';
/** @since 30.0.0 */
case BOOLEAN = 'boolean';
/** @since 30.0.0 */
case DATE = 'date';
/** @since 30.0.0 */
case DATETIME = 'datetime';
/** @since 30.0.0 */
case DECIMAL = 'decimal';
/** @since 30.0.0 */
case FLOAT = 'float';
/** @since 30.0.0 */
case INTEGER = 'integer';
/** @since 30.0.0 */
case SMALLINT = 'smallint';
/** @since 30.0.0 */
case STRING = 'string';
/** @since 30.0.0 */
case TEXT = 'text';
/** @since 30.0.0 */
case TIME = 'time';
/** @since 30.0.0 */
case JSON = 'json';
}
15 changes: 15 additions & 0 deletions lib/public/Migration/Attributes/IndexAdd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Migration\Attributes;

use Attribute;

#[Attribute]

Check failure on line 13 in lib/public/Migration/Attributes/IndexAdd.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

InvalidDocblock

lib/public/Migration/Attributes/IndexAdd.php:13:1: InvalidDocblock: PHPDoc is required for classes/interfaces in OCP. (see https://psalm.dev/008)
class IndexAdd extends IndexMigrationAttribute {
}
37 changes: 37 additions & 0 deletions lib/public/Migration/Attributes/IndexMigrationAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Migration\Attributes;

use Attribute;
use JsonSerializable;

class IndexMigrationAttribute extends MigrationAttribute implements JsonSerializable {

Check failure on line 14 in lib/public/Migration/Attributes/IndexMigrationAttribute.php

View workflow job for this annotation

GitHub Actions / static-code-analysis-ocp

InvalidDocblock

lib/public/Migration/Attributes/IndexMigrationAttribute.php:14:1: InvalidDocblock: PHPDoc is required for classes/interfaces in OCP. (see https://psalm.dev/008)
public function __construct(
string $table,
private readonly ?IndexType $type = null,
MigrationWeight $weight = MigrationWeight::LIGHT,
string $description = '',
array $notes = [],
) {
parent::__construct($table, $weight, $description, $notes);
}

public function getType(): ?IndexType {
return $this->type;
}

public function jsonSerialize(): array {
return array_merge(
parent::jsonSerialize(),
[
'type' => $this->getType() ?? '',
]
);
}
}
15 changes: 15 additions & 0 deletions lib/public/Migration/Attributes/IndexRemove.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Migration\Attributes;

use Attribute;

#[Attribute]
class IndexRemove extends IndexMigrationAttribute {
}
21 changes: 21 additions & 0 deletions lib/public/Migration/Attributes/IndexType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Migration\Attributes;

/**
* @since 30.0.0
*/
enum IndexType : string {
/** @since 30.0.0 */
case PRIMARY = 'primary'; // migration is estimated to require few minutes
/** @since 30.0.0 */
case INDEX = 'index'; // depends on setup, migration might require some time
/** @since 30.0.0 */
case UNIQUE = 'unique'; // migration should be light and quick
}
47 changes: 47 additions & 0 deletions lib/public/Migration/Attributes/MigrationAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Migration\Attributes;

use JsonSerializable;

class MigrationAttribute implements JsonSerializable {
public function __construct(
private readonly string $table,
private readonly MigrationWeight $weight = MigrationWeight::LIGHT,
private readonly string $description = '',
private readonly array $notes = [],
) {
}

public function getTable(): string {
return $this->table;
}

public function getWeight(): MigrationWeight {
return $this->weight;
}

public function getDescription(): string {
return $this->description;
}

public function getNotes(): array {
return $this->notes;
}

public function jsonSerialize(): array {
return [
'class' => get_class($this),
'table' => $this->getTable(),
'weight' => $this->getWeight()->value,
'description' => $this->getDescription(),
'notes' => $this->getNotes(),
];
}
}
22 changes: 22 additions & 0 deletions lib/public/Migration/Attributes/MigrationWeight.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Migration\Attributes;

enum MigrationWeight : string {
/** @since 30.0.0 */
case LIGHT = 'light'; // migration should be light and quick
/** @since 30.0.0 */
case MEDIUM = 'medium'; // migration is estimated to require few minutes
/** @since 30.0.0 */
case SETUP_BASED = 'setup-based'; // depends on setup, migration might require some time
/** @since 30.0.0 */
case SIZE_RELATED = 'size-related'; // depends on setup, migration might require some time
/** @since 30.0.0 */
case HEAVY = 'heavy'; // migration is estimated to be heavy and time consuming
}
15 changes: 15 additions & 0 deletions lib/public/Migration/Attributes/TableCreation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Migration\Attributes;

use Attribute;

#[Attribute]
class TableCreation extends TableMigrationAttribute {
}
15 changes: 15 additions & 0 deletions lib/public/Migration/Attributes/TableDeletion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Migration\Attributes;

use Attribute;

#[Attribute]
class TableDeletion extends MigrationAttribute {
}
37 changes: 37 additions & 0 deletions lib/public/Migration/Attributes/TableMigrationAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCP\Migration\Attributes;

use Attribute;
use JsonSerializable;

class TableMigrationAttribute extends MigrationAttribute implements JsonSerializable {
public function __construct(
string $table,
private readonly array $fields = [],
MigrationWeight $weight = MigrationWeight::LIGHT,
string $description = '',
array $notes = [],
) {
parent::__construct($table, $weight, $description, $notes);
}

public function getFields(): array {
return $this->fields;
}

public function jsonSerialize(): array {
return array_merge(
parent::jsonSerialize(),
[
'fields' => $this->getFields(),
]
);
}
}

0 comments on commit f7638be

Please sign in to comment.