-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
- Loading branch information
There are no files selected for viewing
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 GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
class FieldAdd extends FieldMigrationAttribute { | ||
} |
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 GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
class FieldChange extends FieldMigrationAttribute { | ||
} |
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 GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
public function __construct( | ||
Check failure on line 15 in lib/public/Migration/Attributes/FieldMigrationAttribute.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
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 GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
return $this->field; | ||
} | ||
|
||
public function getType(): ?FieldType { | ||
Check failure on line 30 in lib/public/Migration/Attributes/FieldMigrationAttribute.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
return $this->type; | ||
} | ||
|
||
public function jsonSerialize(): array { | ||
Check failure on line 34 in lib/public/Migration/Attributes/FieldMigrationAttribute.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
return array_merge( | ||
parent::jsonSerialize(), | ||
[ | ||
'field' => $this->getField(), | ||
'type' => $this->getType() ?? '', | ||
] | ||
); | ||
} | ||
} |
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 GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
class FieldRemove extends FieldMigrationAttribute { | ||
} |
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'; | ||
} |
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 GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
class IndexAdd extends IndexMigrationAttribute { | ||
} |
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 GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
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() ?? '', | ||
] | ||
); | ||
} | ||
} |
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 { | ||
} |
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 | ||
} |
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(), | ||
]; | ||
} | ||
} |
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 | ||
} |
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 { | ||
} |
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 { | ||
} |
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(), | ||
] | ||
); | ||
} | ||
} |