diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2024-07-29 10:14:29 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2024-07-29 12:44:52 -0100 |
commit | ad490c963bd88359a714fb2f1786aaf8c00ae17c (patch) | |
tree | 8dddff519102dbb73377fee762c91ff6792a1ad5 /lib/public/Migration | |
parent | 7c1ee524be784bf54d4c09d1310c182593d8b2f2 (diff) | |
download | nextcloud-server-ad490c963bd88359a714fb2f1786aaf8c00ae17c.tar.gz nextcloud-server-ad490c963bd88359a714fb2f1786aaf8c00ae17c.zip |
feat(migration-attributes): tests
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/public/Migration')
14 files changed, 39 insertions, 21 deletions
diff --git a/lib/public/Migration/Attributes/AddColumn.php b/lib/public/Migration/Attributes/AddColumn.php index 14a43c26f99..8d16b9b6e8d 100644 --- a/lib/public/Migration/Attributes/AddColumn.php +++ b/lib/public/Migration/Attributes/AddColumn.php @@ -11,6 +11,8 @@ namespace OCP\Migration\Attributes; use Attribute; /** + * attribute on new column creation + * * @since 30.0.0 */ #[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)] @@ -21,9 +23,8 @@ class AddColumn extends ColumnMigrationAttribute { */ public function definition(): string { $type = is_null($this->getType()) ? '' : ' (' . $this->getType()->value . ')'; - $table = empty($this->getTable()) ? '' : ' to table \'' . $this->getTable() . '\''; return empty($this->getName()) ? - 'Addition of a new column' . $type . $table - : 'Addition of column \'' . $this->getName() . '\'' . $type . $table; + 'Addition of a new column' . $type . ' to table \'' . $this->getTable() . '\'' + : 'Addition of column \'' . $this->getName() . '\'' . $type . ' to table \'' . $this->getTable() . '\''; } } diff --git a/lib/public/Migration/Attributes/AddIndex.php b/lib/public/Migration/Attributes/AddIndex.php index 2a6f0628db1..ee22fe7f128 100644 --- a/lib/public/Migration/Attributes/AddIndex.php +++ b/lib/public/Migration/Attributes/AddIndex.php @@ -11,6 +11,8 @@ namespace OCP\Migration\Attributes; use Attribute; /** + * attribute on index creation + * * @since 30.0.0 */ #[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)] @@ -21,7 +23,6 @@ class AddIndex extends IndexMigrationAttribute { */ public function definition(): string { $type = is_null($this->getType()) ? '' : ' (' . $this->getType()->value . ')'; - $table = empty($this->getTable()) ? '' : ' to table \'' . $this->getTable() . '\''; - return 'Addition of a new index' . $type . $table; + return 'Addition of a new index' . $type . ' to table \'' . $this->getTable() . '\''; } } diff --git a/lib/public/Migration/Attributes/ColumnMigrationAttribute.php b/lib/public/Migration/Attributes/ColumnMigrationAttribute.php index dab636a3aaa..b750932a257 100644 --- a/lib/public/Migration/Attributes/ColumnMigrationAttribute.php +++ b/lib/public/Migration/Attributes/ColumnMigrationAttribute.php @@ -11,11 +11,13 @@ namespace OCP\Migration\Attributes; use JsonSerializable; /** + * generic class related to migration attribute about column changes + * * @since 30.0.0 */ class ColumnMigrationAttribute extends MigrationAttribute implements JsonSerializable { public function __construct( - string $table = '', + string $table, private string $name = '', private ?ColumnType $type = null, string $description = '', diff --git a/lib/public/Migration/Attributes/ColumnType.php b/lib/public/Migration/Attributes/ColumnType.php index 058b74f6516..23445e822b6 100644 --- a/lib/public/Migration/Attributes/ColumnType.php +++ b/lib/public/Migration/Attributes/ColumnType.php @@ -9,7 +9,7 @@ declare(strict_types=1); namespace OCP\Migration\Attributes; /** - * enum FieldType based on OCP\DB\Types + * enum ColumnType based on OCP\DB\Types * * @see \OCP\DB\Types * @since 30.0.0 diff --git a/lib/public/Migration/Attributes/CreateTable.php b/lib/public/Migration/Attributes/CreateTable.php index 8aac8cf247e..df0418fa4bc 100644 --- a/lib/public/Migration/Attributes/CreateTable.php +++ b/lib/public/Migration/Attributes/CreateTable.php @@ -11,6 +11,8 @@ namespace OCP\Migration\Attributes; use Attribute; /** + * attribute on table creation + * * @since 30.0.0 */ #[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)] diff --git a/lib/public/Migration/Attributes/DropColumn.php b/lib/public/Migration/Attributes/DropColumn.php index 0bb3efb1917..1de0ba58489 100644 --- a/lib/public/Migration/Attributes/DropColumn.php +++ b/lib/public/Migration/Attributes/DropColumn.php @@ -11,6 +11,8 @@ namespace OCP\Migration\Attributes; use Attribute; /** + * attribute on column drop + * * @since 30.0.0 */ #[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)] @@ -20,9 +22,8 @@ class DropColumn extends ColumnMigrationAttribute { * @since 30.0.0 */ public function definition(): string { - $table = empty($this->getTable()) ? '' : ' from table \'' . $this->getTable() . '\''; return empty($this->getName()) ? - 'Deletion of a column' . $table - : 'Deletion of column \'' . $this->getName() . '\'' . $table; + 'Deletion of a column from table \'' . $this->getTable() . '\'' + : 'Deletion of column \'' . $this->getName() . '\' from table \'' . $this->getTable() . '\''; } } diff --git a/lib/public/Migration/Attributes/DropIndex.php b/lib/public/Migration/Attributes/DropIndex.php index 0e72908ac35..2702cbed9a7 100644 --- a/lib/public/Migration/Attributes/DropIndex.php +++ b/lib/public/Migration/Attributes/DropIndex.php @@ -11,6 +11,8 @@ namespace OCP\Migration\Attributes; use Attribute; /** + * attribute on index drop + * * @since 30.0.0 */ #[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)] @@ -20,8 +22,6 @@ class DropIndex extends IndexMigrationAttribute { * @since 30.0.0 */ public function definition(): string { - return empty($this->getTable()) ? - 'Deletion of an index' - : 'Deletion of an index from table \'' . $this->getTable() . '\''; + return 'Deletion of an index from table \'' . $this->getTable() . '\''; } } diff --git a/lib/public/Migration/Attributes/DropTable.php b/lib/public/Migration/Attributes/DropTable.php index 5741af14108..e90e4804a3c 100644 --- a/lib/public/Migration/Attributes/DropTable.php +++ b/lib/public/Migration/Attributes/DropTable.php @@ -11,7 +11,9 @@ namespace OCP\Migration\Attributes; use Attribute; /** + * attribute on table drop * + * @since 30.0.0 */ #[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)] class DropTable extends TableMigrationAttribute { diff --git a/lib/public/Migration/Attributes/GenericMigrationAttribute.php b/lib/public/Migration/Attributes/GenericMigrationAttribute.php index 1f40d77d1f1..d0c39a4a1a9 100644 --- a/lib/public/Migration/Attributes/GenericMigrationAttribute.php +++ b/lib/public/Migration/Attributes/GenericMigrationAttribute.php @@ -11,6 +11,9 @@ namespace OCP\Migration\Attributes; use JsonSerializable; /** + * generic entry, used to replace migration attribute not yet known in current version + * but used in a future release + * * @since 30.0.0 */ class GenericMigrationAttribute extends MigrationAttribute implements JsonSerializable { diff --git a/lib/public/Migration/Attributes/IndexMigrationAttribute.php b/lib/public/Migration/Attributes/IndexMigrationAttribute.php index 33c5177c8ac..0d6e946890e 100644 --- a/lib/public/Migration/Attributes/IndexMigrationAttribute.php +++ b/lib/public/Migration/Attributes/IndexMigrationAttribute.php @@ -11,11 +11,13 @@ namespace OCP\Migration\Attributes; use JsonSerializable; /** + * generic class related to migration attribute about index changes + * * @since 30.0.0 */ class IndexMigrationAttribute extends MigrationAttribute implements JsonSerializable { public function __construct( - string $table = '', + string $table, private ?IndexType $type = null, string $description = '', array $notes = [], diff --git a/lib/public/Migration/Attributes/IndexType.php b/lib/public/Migration/Attributes/IndexType.php index b957aebafa7..45c88d81041 100644 --- a/lib/public/Migration/Attributes/IndexType.php +++ b/lib/public/Migration/Attributes/IndexType.php @@ -9,6 +9,8 @@ declare(strict_types=1); namespace OCP\Migration\Attributes; /** + * type of index + * * @since 30.0.0 */ enum IndexType : string { diff --git a/lib/public/Migration/Attributes/MigrationAttribute.php b/lib/public/Migration/Attributes/MigrationAttribute.php index b9d698241d4..19b2ffb56ed 100644 --- a/lib/public/Migration/Attributes/MigrationAttribute.php +++ b/lib/public/Migration/Attributes/MigrationAttribute.php @@ -15,7 +15,7 @@ use JsonSerializable; */ class MigrationAttribute implements JsonSerializable { public function __construct( - private string $table = '', + private string $table, private string $description = '', private array $notes = [], ) { @@ -93,8 +93,7 @@ class MigrationAttribute implements JsonSerializable { * @since 30.0.0 */ public function import(array $data): self { - return $this->setTable($data['table'] ?? '') - ->setDescription($data['description'] ?? '') + return $this->setDescription($data['description'] ?? '') ->setNotes($data['notes'] ?? []); } @@ -107,7 +106,7 @@ class MigrationAttribute implements JsonSerializable { 'class' => get_class($this), 'table' => $this->getTable(), 'description' => $this->getDescription(), - 'notes' => $this->getNotes(), + 'notes' => $this->getNotes() ]; } } diff --git a/lib/public/Migration/Attributes/ModifyColumn.php b/lib/public/Migration/Attributes/ModifyColumn.php index 216a911d90f..ef7250ffb34 100644 --- a/lib/public/Migration/Attributes/ModifyColumn.php +++ b/lib/public/Migration/Attributes/ModifyColumn.php @@ -11,6 +11,8 @@ namespace OCP\Migration\Attributes; use Attribute; /** + * attribute on column modification + * * @since 30.0.0 */ #[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)] @@ -21,9 +23,8 @@ class ModifyColumn extends ColumnMigrationAttribute { */ public function definition(): string { $type = is_null($this->getType()) ? '' : ' to ' . $this->getType()->value; - $table = empty($this->getTable()) ? '' : ' from table \'' . $this->getTable() . '\''; return empty($this->getName()) ? - 'Modification of a column' . $table . $type - : 'Modification of column \'' . $this->getName() . '\'' . $table . $type; + 'Modification of a column from table \'' . $this->getTable() . '\'' . $type + : 'Modification of column \'' . $this->getName() . '\' from table \'' . $this->getTable() . '\'' . $type; } } diff --git a/lib/public/Migration/Attributes/TableMigrationAttribute.php b/lib/public/Migration/Attributes/TableMigrationAttribute.php index 571173b9ba1..f3ba406a4ab 100644 --- a/lib/public/Migration/Attributes/TableMigrationAttribute.php +++ b/lib/public/Migration/Attributes/TableMigrationAttribute.php @@ -11,6 +11,8 @@ namespace OCP\Migration\Attributes; use JsonSerializable; /** + * generic class related to migration attribute about table changes + * * @since 30.0.0 */ class TableMigrationAttribute extends MigrationAttribute implements JsonSerializable { |