mirror of
https://github.com/nextcloud/server.git
synced 2026-06-11 09:42:09 -04:00
fix(migration-attributes): privatizing AttributeException
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
This commit is contained in:
parent
79e6014879
commit
7c1ee524be
19 changed files with 215 additions and 25 deletions
|
|
@ -14,6 +14,9 @@ use Symfony\Component\Console\Command\Command;
|
|||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* @since 30.0.0
|
||||
*/
|
||||
class GenerateMetadataCommand extends Command {
|
||||
public function __construct(
|
||||
private readonly MetadataManager $metadataManager,
|
||||
|
|
@ -43,9 +46,7 @@ class GenerateMetadataCommand extends Command {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function extractMigrationMetadata(): array {
|
||||
private function extractMigrationMetadata(): array {
|
||||
return [
|
||||
'core' => $this->extractMigrationMetadataFromCore(),
|
||||
'apps' => $this->extractMigrationMetadataFromApps()
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@ use Symfony\Component\Console\Input\InputArgument;
|
|||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
/**
|
||||
* @since 30.0.0
|
||||
*/
|
||||
class PreviewCommand extends Command {
|
||||
private bool $initiated = false;
|
||||
public function __construct(
|
||||
|
|
|
|||
|
|
@ -572,7 +572,6 @@ return array(
|
|||
'OCP\\Mail\\IEMailTemplate' => $baseDir . '/lib/public/Mail/IEMailTemplate.php',
|
||||
'OCP\\Mail\\IMailer' => $baseDir . '/lib/public/Mail/IMailer.php',
|
||||
'OCP\\Mail\\IMessage' => $baseDir . '/lib/public/Mail/IMessage.php',
|
||||
<<<<<<< HEAD
|
||||
'OCP\\Mail\\Provider\\Address' => $baseDir . '/lib/public/Mail/Provider/Address.php',
|
||||
'OCP\\Mail\\Provider\\Attachment' => $baseDir . '/lib/public/Mail/Provider/Attachment.php',
|
||||
'OCP\\Mail\\Provider\\Exception\\Exception' => $baseDir . '/lib/public/Mail/Provider/Exception/Exception.php',
|
||||
|
|
@ -585,24 +584,21 @@ return array(
|
|||
'OCP\\Mail\\Provider\\IProvider' => $baseDir . '/lib/public/Mail/Provider/IProvider.php',
|
||||
'OCP\\Mail\\Provider\\IService' => $baseDir . '/lib/public/Mail/Provider/IService.php',
|
||||
'OCP\\Mail\\Provider\\Message' => $baseDir . '/lib/public/Mail/Provider/Message.php',
|
||||
=======
|
||||
'OCP\\Migration\\Attributes\\AddColumn' => $baseDir . '/lib/public/Migration/Attributes/AddColumn.php',
|
||||
'OCP\\Migration\\Attributes\\AddIndex' => $baseDir . '/lib/public/Migration/Attributes/AddIndex.php',
|
||||
'OCP\\Migration\\Attributes\\ColumnMigrationAttribute' => $baseDir . '/lib/public/Migration/Attributes/ColumnMigrationAttribute.php',
|
||||
'OCP\\Migration\\Attributes\\ColumnType' => $baseDir . '/lib/public/Migration/Attributes/ColumnType.php',
|
||||
'OCP\\Migration\\Attributes\\CreateTable' => $baseDir . '/lib/public/Migration/Attributes/CreateTable.php',
|
||||
'OCP\\Migration\\Attributes\\DeleteTable' => $baseDir . '/lib/public/Migration/Attributes/DeleteTable.php',
|
||||
'OCP\\Migration\\Attributes\\DropColumn' => $baseDir . '/lib/public/Migration/Attributes/DropColumn.php',
|
||||
'OCP\\Migration\\Attributes\\DropIndex' => $baseDir . '/lib/public/Migration/Attributes/DropIndex.php',
|
||||
'OCP\\Migration\\Attributes\\DropTable' => $baseDir . '/lib/public/Migration/Attributes/DropTable.php',
|
||||
'OCP\\Migration\\Attributes\\GenericMigrationAttribute' => $baseDir . '/lib/public/Migration/Attributes/GenericMigrationAttribute.php',
|
||||
'OCP\\Migration\\Attributes\\IndexMigrationAttribute' => $baseDir . '/lib/public/Migration/Attributes/IndexMigrationAttribute.php',
|
||||
'OCP\\Migration\\Attributes\\IndexType' => $baseDir . '/lib/public/Migration/Attributes/IndexType.php',
|
||||
'OCP\\Migration\\Attributes\\MigrationAttribute' => $baseDir . '/lib/public/Migration/Attributes/MigrationAttribute.php',
|
||||
'OCP\\Migration\\Attributes\\ModifyColumn' => $baseDir . '/lib/public/Migration/Attributes/ModifyColumn.php',
|
||||
'OCP\\Migration\\Attributes\\TableMigrationAttribute' => $baseDir . '/lib/public/Migration/Attributes/TableMigrationAttribute.php',
|
||||
>>>>>>> 2f771df35a9 (feat(upgrade): migration attributes)
|
||||
'OCP\\Migration\\BigIntMigration' => $baseDir . '/lib/public/Migration/BigIntMigration.php',
|
||||
'OCP\\Migration\\Exceptions\\AttributeException' => $baseDir . '/lib/public/Migration/Exceptions/AttributeException.php',
|
||||
'OCP\\Migration\\IMigrationStep' => $baseDir . '/lib/public/Migration/IMigrationStep.php',
|
||||
'OCP\\Migration\\IOutput' => $baseDir . '/lib/public/Migration/IOutput.php',
|
||||
'OCP\\Migration\\IRepairStep' => $baseDir . '/lib/public/Migration/IRepairStep.php',
|
||||
|
|
@ -1672,6 +1668,8 @@ return array(
|
|||
'OC\\MemoryInfo' => $baseDir . '/lib/private/MemoryInfo.php',
|
||||
'OC\\Migration\\BackgroundRepair' => $baseDir . '/lib/private/Migration/BackgroundRepair.php',
|
||||
'OC\\Migration\\ConsoleOutput' => $baseDir . '/lib/private/Migration/ConsoleOutput.php',
|
||||
'OC\\Migration\\Exceptions\\AttributeException' => $baseDir . '/lib/private/Migration/Exceptions/AttributeException.php',
|
||||
'OC\\Migration\\MetadataManager' => $baseDir . '/lib/private/Migration/MetadataManager.php',
|
||||
'OC\\Migration\\NullOutput' => $baseDir . '/lib/private/Migration/NullOutput.php',
|
||||
'OC\\Migration\\SimpleOutput' => $baseDir . '/lib/private/Migration/SimpleOutput.php',
|
||||
'OC\\NaturalSort' => $baseDir . '/lib/private/NaturalSort.php',
|
||||
|
|
@ -1961,6 +1959,8 @@ return array(
|
|||
'OC\\Updater\\Changes' => $baseDir . '/lib/private/Updater/Changes.php',
|
||||
'OC\\Updater\\ChangesCheck' => $baseDir . '/lib/private/Updater/ChangesCheck.php',
|
||||
'OC\\Updater\\ChangesMapper' => $baseDir . '/lib/private/Updater/ChangesMapper.php',
|
||||
'OC\\Updater\\Exceptions\\ReleaseMetadataException' => $baseDir . '/lib/private/Updater/Exceptions/ReleaseMetadataException.php',
|
||||
'OC\\Updater\\ReleaseMetadata' => $baseDir . '/lib/private/Updater/ReleaseMetadata.php',
|
||||
'OC\\Updater\\VersionCheck' => $baseDir . '/lib/private/Updater/VersionCheck.php',
|
||||
'OC\\UserStatus\\ISettableProvider' => $baseDir . '/lib/private/UserStatus/ISettableProvider.php',
|
||||
'OC\\UserStatus\\Manager' => $baseDir . '/lib/private/UserStatus/Manager.php',
|
||||
|
|
|
|||
|
|
@ -605,7 +605,6 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OCP\\Mail\\IEMailTemplate' => __DIR__ . '/../../..' . '/lib/public/Mail/IEMailTemplate.php',
|
||||
'OCP\\Mail\\IMailer' => __DIR__ . '/../../..' . '/lib/public/Mail/IMailer.php',
|
||||
'OCP\\Mail\\IMessage' => __DIR__ . '/../../..' . '/lib/public/Mail/IMessage.php',
|
||||
<<<<<<< HEAD
|
||||
'OCP\\Mail\\Provider\\Address' => __DIR__ . '/../../..' . '/lib/public/Mail/Provider/Address.php',
|
||||
'OCP\\Mail\\Provider\\Attachment' => __DIR__ . '/../../..' . '/lib/public/Mail/Provider/Attachment.php',
|
||||
'OCP\\Mail\\Provider\\Exception\\Exception' => __DIR__ . '/../../..' . '/lib/public/Mail/Provider/Exception/Exception.php',
|
||||
|
|
@ -618,24 +617,21 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OCP\\Mail\\Provider\\IProvider' => __DIR__ . '/../../..' . '/lib/public/Mail/Provider/IProvider.php',
|
||||
'OCP\\Mail\\Provider\\IService' => __DIR__ . '/../../..' . '/lib/public/Mail/Provider/IService.php',
|
||||
'OCP\\Mail\\Provider\\Message' => __DIR__ . '/../../..' . '/lib/public/Mail/Provider/Message.php',
|
||||
=======
|
||||
'OCP\\Migration\\Attributes\\AddColumn' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/AddColumn.php',
|
||||
'OCP\\Migration\\Attributes\\AddIndex' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/AddIndex.php',
|
||||
'OCP\\Migration\\Attributes\\ColumnMigrationAttribute' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/ColumnMigrationAttribute.php',
|
||||
'OCP\\Migration\\Attributes\\ColumnType' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/ColumnType.php',
|
||||
'OCP\\Migration\\Attributes\\CreateTable' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/CreateTable.php',
|
||||
'OCP\\Migration\\Attributes\\DeleteTable' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/DeleteTable.php',
|
||||
'OCP\\Migration\\Attributes\\DropColumn' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/DropColumn.php',
|
||||
'OCP\\Migration\\Attributes\\DropIndex' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/DropIndex.php',
|
||||
'OCP\\Migration\\Attributes\\DropTable' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/DropTable.php',
|
||||
'OCP\\Migration\\Attributes\\GenericMigrationAttribute' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/GenericMigrationAttribute.php',
|
||||
'OCP\\Migration\\Attributes\\IndexMigrationAttribute' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/IndexMigrationAttribute.php',
|
||||
'OCP\\Migration\\Attributes\\IndexType' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/IndexType.php',
|
||||
'OCP\\Migration\\Attributes\\MigrationAttribute' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/MigrationAttribute.php',
|
||||
'OCP\\Migration\\Attributes\\ModifyColumn' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/ModifyColumn.php',
|
||||
'OCP\\Migration\\Attributes\\TableMigrationAttribute' => __DIR__ . '/../../..' . '/lib/public/Migration/Attributes/TableMigrationAttribute.php',
|
||||
>>>>>>> 2f771df35a9 (feat(upgrade): migration attributes)
|
||||
'OCP\\Migration\\BigIntMigration' => __DIR__ . '/../../..' . '/lib/public/Migration/BigIntMigration.php',
|
||||
'OCP\\Migration\\Exceptions\\AttributeException' => __DIR__ . '/../../..' . '/lib/public/Migration/Exceptions/AttributeException.php',
|
||||
'OCP\\Migration\\IMigrationStep' => __DIR__ . '/../../..' . '/lib/public/Migration/IMigrationStep.php',
|
||||
'OCP\\Migration\\IOutput' => __DIR__ . '/../../..' . '/lib/public/Migration/IOutput.php',
|
||||
'OCP\\Migration\\IRepairStep' => __DIR__ . '/../../..' . '/lib/public/Migration/IRepairStep.php',
|
||||
|
|
@ -1705,6 +1701,8 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OC\\MemoryInfo' => __DIR__ . '/../../..' . '/lib/private/MemoryInfo.php',
|
||||
'OC\\Migration\\BackgroundRepair' => __DIR__ . '/../../..' . '/lib/private/Migration/BackgroundRepair.php',
|
||||
'OC\\Migration\\ConsoleOutput' => __DIR__ . '/../../..' . '/lib/private/Migration/ConsoleOutput.php',
|
||||
'OC\\Migration\\Exceptions\\AttributeException' => __DIR__ . '/../../..' . '/lib/private/Migration/Exceptions/AttributeException.php',
|
||||
'OC\\Migration\\MetadataManager' => __DIR__ . '/../../..' . '/lib/private/Migration/MetadataManager.php',
|
||||
'OC\\Migration\\NullOutput' => __DIR__ . '/../../..' . '/lib/private/Migration/NullOutput.php',
|
||||
'OC\\Migration\\SimpleOutput' => __DIR__ . '/../../..' . '/lib/private/Migration/SimpleOutput.php',
|
||||
'OC\\NaturalSort' => __DIR__ . '/../../..' . '/lib/private/NaturalSort.php',
|
||||
|
|
@ -1994,6 +1992,8 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OC\\Updater\\Changes' => __DIR__ . '/../../..' . '/lib/private/Updater/Changes.php',
|
||||
'OC\\Updater\\ChangesCheck' => __DIR__ . '/../../..' . '/lib/private/Updater/ChangesCheck.php',
|
||||
'OC\\Updater\\ChangesMapper' => __DIR__ . '/../../..' . '/lib/private/Updater/ChangesMapper.php',
|
||||
'OC\\Updater\\Exceptions\\ReleaseMetadataException' => __DIR__ . '/../../..' . '/lib/private/Updater/Exceptions/ReleaseMetadataException.php',
|
||||
'OC\\Updater\\ReleaseMetadata' => __DIR__ . '/../../..' . '/lib/private/Updater/ReleaseMetadata.php',
|
||||
'OC\\Updater\\VersionCheck' => __DIR__ . '/../../..' . '/lib/private/Updater/VersionCheck.php',
|
||||
'OC\\UserStatus\\ISettableProvider' => __DIR__ . '/../../..' . '/lib/private/UserStatus/ISettableProvider.php',
|
||||
'OC\\UserStatus\\Manager' => __DIR__ . '/../../..' . '/lib/private/UserStatus/Manager.php',
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ declare(strict_types=1);
|
|||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
namespace OCP\Migration\Exceptions;
|
||||
namespace OC\Migration\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
|
|
@ -10,10 +10,10 @@ namespace OC\Migration;
|
|||
|
||||
use OC\DB\Connection;
|
||||
use OC\DB\MigrationService;
|
||||
use OC\Migration\Exceptions\AttributeException;
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\Migration\Attributes\GenericMigrationAttribute;
|
||||
use OCP\Migration\Attributes\MigrationAttribute;
|
||||
use OCP\Migration\Exceptions\AttributeException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use ReflectionClass;
|
||||
|
||||
|
|
@ -58,10 +58,10 @@ class MetadataManager {
|
|||
/**
|
||||
* convert direct data from release metadata into a list of Migrations' Attribute
|
||||
*
|
||||
* @param array $metadata
|
||||
* @param array<array-key, array<array-key, array>> $metadata
|
||||
* @param bool $filterKnownMigrations ignore metadata already done in local instance
|
||||
*
|
||||
* @return array
|
||||
* @return array{apps: array<array-key, array<string, MigrationAttribute[]>>, core: array<string, MigrationAttribute[]>}
|
||||
* @since 30.0.0
|
||||
*/
|
||||
public function getMigrationsAttributesFromReleaseMetadata(
|
||||
|
|
@ -73,6 +73,7 @@ class MetadataManager {
|
|||
if ($filterKnownMigrations && !$this->appManager->isInstalled($appId)) {
|
||||
continue; // if not interested and app is not installed
|
||||
}
|
||||
|
||||
$done = ($filterKnownMigrations) ? $this->getKnownMigrations($appId) : [];
|
||||
$appsAttributes[$appId] = $this->parseMigrations($metadata['apps'][$appId] ?? [], $done);
|
||||
}
|
||||
|
|
@ -126,7 +127,6 @@ class MetadataManager {
|
|||
return $ms->getMigratedVersions();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* generate (deserialize) a MigrationAttribute from a serialized version
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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() . '\'';
|
||||
|
|
|
|||
|
|
@ -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() . '\'';
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()) ?
|
||||
|
|
|
|||
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -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() . '\'';
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
|
|
|
|||
|
|
@ -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() . '\'';
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue