nextcloud/lib/public/Migration/Attributes/ColumnMigrationAttribute.php
Maxence Lange 88cfab4f32 feat(upgrade): migration attributes
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>

d

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>

f

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>

d

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
2024-07-29 12:44:52 -01:00

58 lines
1.2 KiB
PHP

<?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 ColumnMigrationAttribute extends MigrationAttribute implements JsonSerializable {
public function __construct(
string $table = '',
private string $name = '',
private ?ColumnType $type = null,
string $description = '',
array $notes = [],
) {
parent::__construct($table, $description, $notes);
}
public function setName(string $name): self {
$this->name = $name;
return $this;
}
public function getName(): string {
return $this->name;
}
public function setType(?ColumnType $type): self {
$this->type = $type;
return $this;
}
public function getType(): ?ColumnType {
return $this->type;
}
public function import(array $data): self {
parent::import($data);
$this->setName($data['name'] ?? '');
$this->setType(ColumnType::tryFrom($data['type'] ?? ''));
return $this;
}
public function jsonSerialize(): array {
return array_merge(
parent::jsonSerialize(),
[
'name' => $this->getName(),
'type' => $this->getType() ?? '',
]
);
}
}