Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"php": ">=8.1",
"ext-curl": "*",
"ext-openssl": "*",
"appwrite/appwrite": "19.*",
"appwrite/appwrite": "20.*",
"utopia-php/database": "5.*",
"utopia-php/storage": "1.0.*",
"utopia-php/dsn": "0.2.*",
Expand Down
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions src/Migration/Destinations/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public function __construct(
string $endpoint,
string $key,
protected UtopiaDatabase $dbForProject,
callable $getDatabasesDB,
protected array $collectionStructure
?callable $getDatabasesDB = null,
protected array $collectionStructure = []
) {
$this->project = $project;
$this->endpoint = $endpoint;
Expand Down Expand Up @@ -169,6 +169,9 @@ public static function getSupportedResources(): array
Resource::TYPE_SITE,
Resource::TYPE_SITE_DEPLOYMENT,
Resource::TYPE_SITE_VARIABLE,

// Backups
Resource::TYPE_BACKUP_POLICY,
];
}

Expand Down Expand Up @@ -324,6 +327,7 @@ protected function import(array $resources, callable $callback): void
Transfer::GROUP_AUTH => $this->importAuthResource($resource),
Transfer::GROUP_FUNCTIONS => $this->importFunctionResource($resource),
Transfer::GROUP_MESSAGING => $this->importMessagingResource($resource),
Transfer::GROUP_BACKUPS => $this->importBackupResource($resource),
Transfer::GROUP_SITES => $this->importSiteResource($resource),
default => throw new \Exception('Invalid resource group', Exception::CODE_VALIDATION),
};
Expand Down Expand Up @@ -1479,6 +1483,13 @@ public function importFunctionResource(Resource $resource): Resource
return $resource;
}

public function importBackupResource(Resource $resource): Resource
{
$resource->setStatus(Resource::STATUS_SUCCESS);

return $resource;
}

/**
* @throws AppwriteException
* @throws \Exception
Expand Down
4 changes: 4 additions & 0 deletions src/Migration/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ abstract class Resource implements \JsonSerializable

public const TYPE_MESSAGE = 'message';

// Backups
public const TYPE_BACKUP_POLICY = 'backup-policy';

// legacy terminologies
public const TYPE_DOCUMENT = 'document';
public const TYPE_ATTRIBUTE = 'attribute';
Expand Down Expand Up @@ -110,6 +113,7 @@ abstract class Resource implements \JsonSerializable
self::TYPE_TOPIC,
self::TYPE_SUBSCRIBER,
self::TYPE_MESSAGE,
self::TYPE_BACKUP_POLICY,

// legacy
self::TYPE_DOCUMENT,
Expand Down
115 changes: 115 additions & 0 deletions src/Migration/Resources/Backups/Policy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

namespace Utopia\Migration\Resources\Backups;

use Utopia\Migration\Resource;
use Utopia\Migration\Transfer;

class Policy extends Resource
{
/**
* @param string $id
* @param string $name
* @param array<string> $services
* @param int $retention
* @param string $schedule
* @param bool $enabled
* @param string $resourceId
* @param string $resourceType
*/
public function __construct(
string $id = '',
private readonly string $name = '',
private readonly array $services = [],
private readonly int $retention = 0,
private readonly string $schedule = '',
private readonly bool $enabled = true,
private readonly string $resourceId = '',
private readonly string $resourceType = '',
) {
$this->id = $id;
}

/**
* @param array<string, mixed> $array
* @return self
*/
public static function fromArray(array $array): self
{
return new self(
$array['id'],
$array['name'] ?? '',
$array['services'] ?? [],
$array['retention'] ?? 0,
$array['schedule'] ?? '',
$array['enabled'] ?? true,
$array['resourceId'] ?? '',
$array['resourceType'] ?? '',
);
}

/**
* @return array<string, mixed>
*/
public function jsonSerialize(): array
{
return [
'id' => $this->id,
'name' => $this->name,
'services' => $this->services,
'retention' => $this->retention,
'schedule' => $this->schedule,
'enabled' => $this->enabled,
'resourceId' => $this->resourceId,
'resourceType' => $this->resourceType,
];
}

public static function getName(): string
{
return Resource::TYPE_BACKUP_POLICY;
}

public function getGroup(): string
{
return Transfer::GROUP_BACKUPS;
}

public function getPolicyName(): string
{
return $this->name;
}

/**
* @return array<string>
*/
public function getServices(): array
{
return $this->services;
}

public function getRetention(): int
{
return $this->retention;
}

public function getSchedule(): string
{
return $this->schedule;
}

public function getEnabled(): bool
{
return $this->enabled;
}

public function getResourceId(): string
{
return $this->resourceId;
}

public function getResourceType(): string
{
return $this->resourceType;
}
}
2 changes: 1 addition & 1 deletion src/Migration/Resources/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function fromArray(array $array): self
enabled: $array['enabled'] ?? true,
originalId: $array['originalId'] ?? '',
type: $array['type'] ?? 'legacy',
database: $array['database']
database: $array['database'] ?? ''
);
}

Expand Down
17 changes: 17 additions & 0 deletions src/Migration/Source.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public function getMessagingBatchSize(): int
return static::$defaultBatchSize;
}

public function getBackupsBatchSize(): int
{
return static::$defaultBatchSize;
}

public function getSitesBatchSize(): int
{
return static::$defaultBatchSize;
Expand Down Expand Up @@ -108,6 +113,7 @@ public function exportResources(array $resources): void
Transfer::GROUP_STORAGE => Transfer::GROUP_STORAGE_RESOURCES,
Transfer::GROUP_FUNCTIONS => Transfer::GROUP_FUNCTIONS_RESOURCES,
Transfer::GROUP_MESSAGING => Transfer::GROUP_MESSAGING_RESOURCES,
Transfer::GROUP_BACKUPS => Transfer::GROUP_BACKUPS_RESOURCES,
Transfer::GROUP_SITES => Transfer::GROUP_SITES_RESOURCES,
];

Expand Down Expand Up @@ -140,6 +146,9 @@ public function exportResources(array $resources): void
case Transfer::GROUP_MESSAGING:
$this->exportGroupMessaging($this->getMessagingBatchSize(), $resources);
break;
case Transfer::GROUP_BACKUPS:
$this->exportGroupBackups($this->getBackupsBatchSize(), $resources);
break;
case Transfer::GROUP_SITES:
$this->exportGroupSites($this->getSitesBatchSize(), $resources);
break;
Expand Down Expand Up @@ -187,6 +196,14 @@ abstract protected function exportGroupFunctions(int $batchSize, array $resource
*/
abstract protected function exportGroupMessaging(int $batchSize, array $resources): void;

/**
* Export Backups Group
*
* @param int $batchSize
* @param array<string> $resources Resources to export
*/
abstract protected function exportGroupBackups(int $batchSize, array $resources): void;

/**
* Export Sites Group
*
Expand Down
Loading
Loading