aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/Migration
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2024-07-26 16:35:51 -0100
committerMaxence Lange <maxence@artificial-owl.com>2024-07-29 12:44:52 -0100
commit7c1ee524be784bf54d4c09d1310c182593d8b2f2 (patch)
treeb912f145ed38af7612f9cb919365b6845b578236 /lib/public/Migration
parent79e60148799eee50b08c5edf07b91ba8428642fd (diff)
downloadnextcloud-server-7c1ee524be784bf54d4c09d1310c182593d8b2f2.tar.gz
nextcloud-server-7c1ee524be784bf54d4c09d1310c182593d8b2f2.zip
fix(migration-attributes): privatizing AttributeException
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/public/Migration')
-rw-r--r--lib/public/Migration/Attributes/AddColumn.php7
-rw-r--r--lib/public/Migration/Attributes/AddIndex.php7
-rw-r--r--lib/public/Migration/Attributes/ColumnMigrationAttribute.php33
-rw-r--r--lib/public/Migration/Attributes/CreateTable.php9
-rw-r--r--lib/public/Migration/Attributes/DropColumn.php7
-rw-r--r--lib/public/Migration/Attributes/DropIndex.php7
-rw-r--r--lib/public/Migration/Attributes/DropTable.php (renamed from lib/public/Migration/Attributes/DeleteTable.php)11
-rw-r--r--lib/public/Migration/Attributes/GenericMigrationAttribute.php11
-rw-r--r--lib/public/Migration/Attributes/IndexMigrationAttribute.php23
-rw-r--r--lib/public/Migration/Attributes/IndexType.php6
-rw-r--r--lib/public/Migration/Attributes/MigrationAttribute.php47
-rw-r--r--lib/public/Migration/Attributes/ModifyColumn.php7
-rw-r--r--lib/public/Migration/Attributes/TableMigrationAttribute.php25
-rw-r--r--lib/public/Migration/Exceptions/AttributeException.php17
14 files changed, 193 insertions, 24 deletions
diff --git a/lib/public/Migration/Attributes/AddColumn.php b/lib/public/Migration/Attributes/AddColumn.php
index aadf3263b31..14a43c26f99 100644
--- a/lib/public/Migration/Attributes/AddColumn.php
+++ b/lib/public/Migration/Attributes/AddColumn.php
@@ -10,8 +10,15 @@ namespace OCP\Migration\Attributes;
use Attribute;
+/**
+ * @since 30.0.0
+ */
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
class AddColumn extends ColumnMigrationAttribute {
+ /**
+ * @return string
+ * @since 30.0.0
+ */
public function definition(): string {
$type = is_null($this->getType()) ? '' : ' (' . $this->getType()->value . ')';
$table = empty($this->getTable()) ? '' : ' to table \'' . $this->getTable() . '\'';
diff --git a/lib/public/Migration/Attributes/AddIndex.php b/lib/public/Migration/Attributes/AddIndex.php
index 9c96cd49a12..2a6f0628db1 100644
--- a/lib/public/Migration/Attributes/AddIndex.php
+++ b/lib/public/Migration/Attributes/AddIndex.php
@@ -10,8 +10,15 @@ namespace OCP\Migration\Attributes;
use Attribute;
+/**
+ * @since 30.0.0
+ */
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
class AddIndex extends IndexMigrationAttribute {
+ /**
+ * @return string
+ * @since 30.0.0
+ */
public function definition(): string {
$type = is_null($this->getType()) ? '' : ' (' . $this->getType()->value . ')';
$table = empty($this->getTable()) ? '' : ' to table \'' . $this->getTable() . '\'';
diff --git a/lib/public/Migration/Attributes/ColumnMigrationAttribute.php b/lib/public/Migration/Attributes/ColumnMigrationAttribute.php
index 6862f73e11d..dab636a3aaa 100644
--- a/lib/public/Migration/Attributes/ColumnMigrationAttribute.php
+++ b/lib/public/Migration/Attributes/ColumnMigrationAttribute.php
@@ -10,6 +10,9 @@ namespace OCP\Migration\Attributes;
use JsonSerializable;
+/**
+ * @since 30.0.0
+ */
class ColumnMigrationAttribute extends MigrationAttribute implements JsonSerializable {
public function __construct(
string $table = '',
@@ -21,24 +24,50 @@ class ColumnMigrationAttribute extends MigrationAttribute implements JsonSeriali
parent::__construct($table, $description, $notes);
}
+ /**
+ * @param string $name
+ *
+ * @return $this
+ * @since 30.0.0
+ */
public function setName(string $name): self {
$this->name = $name;
return $this;
}
+ /**
+ * @return string
+ * @since 30.0.0
+ */
public function getName(): string {
return $this->name;
}
+ /**
+ * @param ColumnType|null $type
+ *
+ * @return $this
+ * @since 30.0.0
+ */
public function setType(?ColumnType $type): self {
$this->type = $type;
return $this;
}
+ /**
+ * @return ColumnType|null
+ * @since 30.0.0
+ */
public function getType(): ?ColumnType {
return $this->type;
}
+ /**
+ * @param array $data
+ *
+ * @return $this
+ * @since 30.0.0
+ */
public function import(array $data): self {
parent::import($data);
$this->setName($data['name'] ?? '');
@@ -46,6 +75,10 @@ class ColumnMigrationAttribute extends MigrationAttribute implements JsonSeriali
return $this;
}
+ /**
+ * @return array
+ * @since 30.0.0
+ */
public function jsonSerialize(): array {
return array_merge(
parent::jsonSerialize(),
diff --git a/lib/public/Migration/Attributes/CreateTable.php b/lib/public/Migration/Attributes/CreateTable.php
index 600d9bf4b9f..8aac8cf247e 100644
--- a/lib/public/Migration/Attributes/CreateTable.php
+++ b/lib/public/Migration/Attributes/CreateTable.php
@@ -10,10 +10,17 @@ namespace OCP\Migration\Attributes;
use Attribute;
+/**
+ * @since 30.0.0
+ */
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
class CreateTable extends TableMigrationAttribute {
+ /**
+ * @return string
+ * @since 30.0.0
+ */
public function definition(): string {
- $definition = empty($this->getTable()) ? 'Creation of a new table' : 'Creation of new table \'' . $this->getTable() . '\'';
+ $definition = 'Creation of new table \'' . $this->getTable() . '\'';
$definition .= empty($this->getColumns()) ? '' : ' with columns ' . implode(', ', $this->getColumns());
return $definition;
}
diff --git a/lib/public/Migration/Attributes/DropColumn.php b/lib/public/Migration/Attributes/DropColumn.php
index dfa1e81b315..0bb3efb1917 100644
--- a/lib/public/Migration/Attributes/DropColumn.php
+++ b/lib/public/Migration/Attributes/DropColumn.php
@@ -10,8 +10,15 @@ namespace OCP\Migration\Attributes;
use Attribute;
+/**
+ * @since 30.0.0
+ */
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
class DropColumn extends ColumnMigrationAttribute {
+ /**
+ * @return string
+ * @since 30.0.0
+ */
public function definition(): string {
$table = empty($this->getTable()) ? '' : ' from table \'' . $this->getTable() . '\'';
return empty($this->getName()) ?
diff --git a/lib/public/Migration/Attributes/DropIndex.php b/lib/public/Migration/Attributes/DropIndex.php
index cbeea4f5997..0e72908ac35 100644
--- a/lib/public/Migration/Attributes/DropIndex.php
+++ b/lib/public/Migration/Attributes/DropIndex.php
@@ -10,8 +10,15 @@ namespace OCP\Migration\Attributes;
use Attribute;
+/**
+ * @since 30.0.0
+ */
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
class DropIndex extends IndexMigrationAttribute {
+ /**
+ * @return string
+ * @since 30.0.0
+ */
public function definition(): string {
return empty($this->getTable()) ?
'Deletion of an index'
diff --git a/lib/public/Migration/Attributes/DeleteTable.php b/lib/public/Migration/Attributes/DropTable.php
index 97bd36e385e..5741af14108 100644
--- a/lib/public/Migration/Attributes/DeleteTable.php
+++ b/lib/public/Migration/Attributes/DropTable.php
@@ -10,9 +10,16 @@ namespace OCP\Migration\Attributes;
use Attribute;
+/**
+ *
+ */
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
-class DeleteTable extends MigrationAttribute {
+class DropTable extends TableMigrationAttribute {
+ /**
+ * @return string
+ * @since 30.0.0
+ */
public function definition(): string {
- return empty($this->getTable()) ? 'Deletion of a table' : 'Deletion of table \'' . $this->getTable() . '\'';
+ return 'Deletion of table \'' . $this->getTable() . '\'';
}
}
diff --git a/lib/public/Migration/Attributes/GenericMigrationAttribute.php b/lib/public/Migration/Attributes/GenericMigrationAttribute.php
index f0e3af97615..1f40d77d1f1 100644
--- a/lib/public/Migration/Attributes/GenericMigrationAttribute.php
+++ b/lib/public/Migration/Attributes/GenericMigrationAttribute.php
@@ -10,6 +10,9 @@ namespace OCP\Migration\Attributes;
use JsonSerializable;
+/**
+ * @since 30.0.0
+ */
class GenericMigrationAttribute extends MigrationAttribute implements JsonSerializable {
public function __construct(
private readonly array $details = []
@@ -21,10 +24,18 @@ class GenericMigrationAttribute extends MigrationAttribute implements JsonSerial
);
}
+ /**
+ * @return string
+ * @since 30.0.0
+ */
public function definition(): string {
return json_encode($this->jsonSerialize(), JSON_UNESCAPED_SLASHES);
}
+ /**
+ * @return array
+ * @since 30.0.0
+ */
public function jsonSerialize(): array {
return $this->details;
}
diff --git a/lib/public/Migration/Attributes/IndexMigrationAttribute.php b/lib/public/Migration/Attributes/IndexMigrationAttribute.php
index fbe636bd6b0..33c5177c8ac 100644
--- a/lib/public/Migration/Attributes/IndexMigrationAttribute.php
+++ b/lib/public/Migration/Attributes/IndexMigrationAttribute.php
@@ -10,6 +10,9 @@ namespace OCP\Migration\Attributes;
use JsonSerializable;
+/**
+ * @since 30.0.0
+ */
class IndexMigrationAttribute extends MigrationAttribute implements JsonSerializable {
public function __construct(
string $table = '',
@@ -20,21 +23,41 @@ class IndexMigrationAttribute extends MigrationAttribute implements JsonSerializ
parent::__construct($table, $description, $notes);
}
+ /**
+ * @param IndexType|null $type
+ *
+ * @return $this
+ * @since 30.0.0
+ */
public function setType(?IndexType $type): self {
$this->type = $type;
return $this;
}
+ /**
+ * @return IndexType|null
+ * @since 30.0.0
+ */
public function getType(): ?IndexType {
return $this->type;
}
+ /**
+ * @param array $data
+ *
+ * @return $this
+ * @since 30.0.0
+ */
public function import(array $data): self {
parent::import($data);
$this->setType(IndexType::tryFrom($data['type'] ?? ''));
return $this;
}
+ /**
+ * @return array
+ * @since 30.0.0
+ */
public function jsonSerialize(): array {
return array_merge(
parent::jsonSerialize(),
diff --git a/lib/public/Migration/Attributes/IndexType.php b/lib/public/Migration/Attributes/IndexType.php
index 842f135e700..b957aebafa7 100644
--- a/lib/public/Migration/Attributes/IndexType.php
+++ b/lib/public/Migration/Attributes/IndexType.php
@@ -13,9 +13,9 @@ namespace OCP\Migration\Attributes;
*/
enum IndexType : string {
/** @since 30.0.0 */
- case PRIMARY = 'primary'; // migration is estimated to require few minutes
+ case PRIMARY = 'primary';
/** @since 30.0.0 */
- case INDEX = 'index'; // depends on setup, migration might require some time
+ case INDEX = 'index';
/** @since 30.0.0 */
- case UNIQUE = 'unique'; // migration should be light and quick
+ case UNIQUE = 'unique';
}
diff --git a/lib/public/Migration/Attributes/MigrationAttribute.php b/lib/public/Migration/Attributes/MigrationAttribute.php
index 9f88614e37d..b9d698241d4 100644
--- a/lib/public/Migration/Attributes/MigrationAttribute.php
+++ b/lib/public/Migration/Attributes/MigrationAttribute.php
@@ -10,6 +10,9 @@ namespace OCP\Migration\Attributes;
use JsonSerializable;
+/**
+ * @since 30.0.0
+ */
class MigrationAttribute implements JsonSerializable {
public function __construct(
private string $table = '',
@@ -18,43 +21,87 @@ class MigrationAttribute implements JsonSerializable {
) {
}
+ /**
+ * @param string $table
+ *
+ * @return $this
+ * @since 30.0.0
+ */
public function setTable(string $table): self {
$this->table = $table;
return $this;
}
+ /**
+ * @return string
+ * @since 30.0.0
+ */
public function getTable(): string {
return $this->table;
}
+ /**
+ * @param string $description
+ *
+ * @return $this
+ * @since 30.0.0
+ */
public function setDescription(string $description): self {
$this->description = $description;
return $this;
}
+ /**
+ * @return string
+ * @since 30.0.0
+ */
public function getDescription(): string {
return $this->description;
}
+ /**
+ * @param array $notes
+ *
+ * @return $this
+ * @since 30.0.0
+ */
public function setNotes(array $notes): self {
$this->notes = $notes;
return $this;
}
+ /**
+ * @return array
+ * @since 30.0.0
+ */
public function getNotes(): array {
return $this->notes;
}
+ /**
+ * @return string
+ * @since 30.0.0
+ */
public function definition(): string {
return json_encode($this->jsonSerialize(), JSON_UNESCAPED_SLASHES);
}
+ /**
+ * @param array $data
+ *
+ * @return self
+ * @since 30.0.0
+ */
public function import(array $data): self {
return $this->setTable($data['table'] ?? '')
->setDescription($data['description'] ?? '')
->setNotes($data['notes'] ?? []);
}
+ /**
+ * @return array
+ * @since 30.0.0
+ */
public function jsonSerialize(): array {
return [
'class' => get_class($this),
diff --git a/lib/public/Migration/Attributes/ModifyColumn.php b/lib/public/Migration/Attributes/ModifyColumn.php
index e73b10478f7..216a911d90f 100644
--- a/lib/public/Migration/Attributes/ModifyColumn.php
+++ b/lib/public/Migration/Attributes/ModifyColumn.php
@@ -10,8 +10,15 @@ namespace OCP\Migration\Attributes;
use Attribute;
+/**
+ * @since 30.0.0
+ */
#[Attribute(Attribute::IS_REPEATABLE | Attribute::TARGET_CLASS)]
class ModifyColumn extends ColumnMigrationAttribute {
+ /**
+ * @return string
+ * @since 30.0.0
+ */
public function definition(): string {
$type = is_null($this->getType()) ? '' : ' to ' . $this->getType()->value;
$table = empty($this->getTable()) ? '' : ' from table \'' . $this->getTable() . '\'';
diff --git a/lib/public/Migration/Attributes/TableMigrationAttribute.php b/lib/public/Migration/Attributes/TableMigrationAttribute.php
index 1c3f90c6acf..571173b9ba1 100644
--- a/lib/public/Migration/Attributes/TableMigrationAttribute.php
+++ b/lib/public/Migration/Attributes/TableMigrationAttribute.php
@@ -10,9 +10,12 @@ namespace OCP\Migration\Attributes;
use JsonSerializable;
+/**
+ * @since 30.0.0
+ */
class TableMigrationAttribute extends MigrationAttribute implements JsonSerializable {
public function __construct(
- string $table = '',
+ string $table,
private array $columns = [],
string $description = '',
array $notes = [],
@@ -20,21 +23,41 @@ class TableMigrationAttribute extends MigrationAttribute implements JsonSerializ
parent::__construct($table, $description, $notes);
}
+ /**
+ * @param array $columns
+ *
+ * @return $this
+ * @since 30.0.0
+ */
public function setColumns(array $columns): self {
$this->columns = $columns;
return $this;
}
+ /**
+ * @return array
+ * @since 30.0.0
+ */
public function getColumns(): array {
return $this->columns;
}
+ /**
+ * @param array $data
+ *
+ * @return $this
+ * @since 30.0.0
+ */
public function import(array $data): self {
parent::import($data);
$this->setColumns($data['columns'] ?? []);
return $this;
}
+ /**
+ * @return array
+ * @since 30.0.0
+ */
public function jsonSerialize(): array {
return array_merge(
parent::jsonSerialize(),
diff --git a/lib/public/Migration/Exceptions/AttributeException.php b/lib/public/Migration/Exceptions/AttributeException.php
deleted file mode 100644
index 92de70f3e96..00000000000
--- a/lib/public/Migration/Exceptions/AttributeException.php
+++ /dev/null
@@ -1,17 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-namespace OCP\Migration\Exceptions;
-
-use Exception;
-
-/**
- * @since 30.0.0
- */
-class AttributeException extends Exception {
-}