Add Services migration

Singleton settings resource carrying 17 per-service enable/disable flags
(Account, Avatars, Databases, TablesDB, Locale, Health, Project, Storage,
Teams, Users, VCS, Sites, Functions, Proxy, GraphQL, Migrations, Messaging).
Source reads via raw GET /v1/project; destination flips each via
Project::updateService().
This commit is contained in:
Prem Palanisamy committed 2026-05-18 16:10:10 +01:00
1 parent b7b64ac3ed
commit 2f72707343
5 files changed
+299

No files matched your search

+41
View File
@@ -12,6 +12,7 @@ use Appwrite\Enums\Framework;
use Appwrite\Enums\PasswordHash;
use Appwrite\Enums\ProtocolId;
use Appwrite\Enums\Runtime;
use Appwrite\Enums\ServiceId;
use Appwrite\Enums\SmtpEncryption;
use Appwrite\InputFile;
use Appwrite\Services\Functions;
@@ -63,6 +64,7 @@ use Utopia\Migration\Resources\Messaging\Topic;
use Utopia\Migration\Resources\Settings\Labels;
use Utopia\Migration\Resources\Settings\ProjectVariable;
use Utopia\Migration\Resources\Settings\Protocols;
use Utopia\Migration\Resources\Settings\Services as ServicesResource;
use Utopia\Migration\Resources\Settings\Webhook;
use Utopia\Migration\Resources\Sites\Deployment as SiteDeployment;
use Utopia\Migration\Resources\Sites\EnvVar as SiteEnvVar;
@@ -294,6 +296,7 @@ class Appwrite extends Destination
Resource::TYPE_WEBHOOK,
Resource::TYPE_PROTOCOLS,
Resource::TYPE_LABELS,
Resource::TYPE_SERVICES,
// Backups
Resource::TYPE_BACKUP_POLICY,
@@ -3130,6 +3133,10 @@ class Appwrite extends Destination
/** @var Labels $resource */
$this->createLabels($resource);
break;
case Resource::TYPE_SERVICES:
/** @var ServicesResource $resource */
$this->createServices($resource);
break;
}
if ($resource->getStatus() !== Resource::STATUS_SKIPPED) {
@@ -3209,6 +3216,40 @@ class Appwrite extends Destination
return true;
}
/**
* Flip each service flag on the destination via the SDK. 17 single-field
* updates rather than one bulk write — the SDK only exposes per-service
* setters, matching upstream's per-flag controller.
*/
protected function createServices(ServicesResource $resource): bool
{
$flags = [
[ServiceId::ACCOUNT(), $resource->getAccount()],
[ServiceId::AVATARS(), $resource->getAvatars()],
[ServiceId::DATABASES(), $resource->getDatabases()],
[ServiceId::TABLESDB(), $resource->getTablesdb()],
[ServiceId::LOCALE(), $resource->getLocale()],
[ServiceId::HEALTH(), $resource->getHealth()],
[ServiceId::PROJECT(), $resource->getProject()],
[ServiceId::STORAGE(), $resource->getStorage()],
[ServiceId::TEAMS(), $resource->getTeams()],
[ServiceId::USERS(), $resource->getUsers()],
[ServiceId::VCS(), $resource->getVcs()],
[ServiceId::SITES(), $resource->getSites()],
[ServiceId::FUNCTIONS(), $resource->getFunctions()],
[ServiceId::PROXY(), $resource->getProxy()],
[ServiceId::GRAPHQL(), $resource->getGraphql()],
[ServiceId::MIGRATIONS(), $resource->getMigrations()],
[ServiceId::MESSAGING(), $resource->getMessaging()],
];
foreach ($flags as [$service, $enabled]) {
$this->project->updateService($service, $enabled);
}
return true;
}
protected function createWebhook(Webhook $resource): bool
{
$existing = $this->dbForPlatform->findOne('webhooks', [
+2
View File
@@ -82,6 +82,7 @@ abstract class Resource implements \JsonSerializable
public const TYPE_WEBHOOK = 'webhook';
public const TYPE_PROTOCOLS = 'protocols';
public const TYPE_LABELS = 'labels';
public const TYPE_SERVICES = 'services';
// Messaging
public const TYPE_SUBSCRIBER = 'subscriber';
@@ -128,6 +129,7 @@ abstract class Resource implements \JsonSerializable
self::TYPE_WEBHOOK,
self::TYPE_PROTOCOLS,
self::TYPE_LABELS,
self::TYPE_SERVICES,
self::TYPE_PROVIDER,
self::TYPE_TOPIC,
self::TYPE_SUBSCRIBER,
@@ -0,0 +1,194 @@
<?php
namespace Utopia\Migration\Resources\Settings;
use Utopia\Migration\Resource;
use Utopia\Migration\Transfer;
/**
* Singleton settings resource carrying the project's 17 per-service
* enable/disable flags. One per project; destination flips each via
* Project::updateService().
*/
class Services extends Resource
{
public function __construct(
string $id,
private readonly bool $account = true,
private readonly bool $avatars = true,
private readonly bool $databases = true,
private readonly bool $tablesdb = true,
private readonly bool $locale = true,
private readonly bool $health = true,
private readonly bool $project = true,
private readonly bool $storage = true,
private readonly bool $teams = true,
private readonly bool $users = true,
private readonly bool $vcs = true,
private readonly bool $sites = true,
private readonly bool $functions = true,
private readonly bool $proxy = true,
private readonly bool $graphql = true,
private readonly bool $migrations = true,
private readonly bool $messaging = true,
string $createdAt = '',
string $updatedAt = '',
) {
$this->id = $id;
$this->createdAt = $createdAt;
$this->updatedAt = $updatedAt;
}
/**
* @param array<string, mixed> $array
*/
public static function fromArray(array $array): self
{
return new self(
$array['id'],
(bool) ($array['account'] ?? true),
(bool) ($array['avatars'] ?? true),
(bool) ($array['databases'] ?? true),
(bool) ($array['tablesdb'] ?? true),
(bool) ($array['locale'] ?? true),
(bool) ($array['health'] ?? true),
(bool) ($array['project'] ?? true),
(bool) ($array['storage'] ?? true),
(bool) ($array['teams'] ?? true),
(bool) ($array['users'] ?? true),
(bool) ($array['vcs'] ?? true),
(bool) ($array['sites'] ?? true),
(bool) ($array['functions'] ?? true),
(bool) ($array['proxy'] ?? true),
(bool) ($array['graphql'] ?? true),
(bool) ($array['migrations'] ?? true),
(bool) ($array['messaging'] ?? true),
createdAt: $array['createdAt'] ?? '',
updatedAt: $array['updatedAt'] ?? '',
);
}
/**
* @return array<string, mixed>
*/
public function jsonSerialize(): array
{
return [
'id' => $this->id,
'account' => $this->account,
'avatars' => $this->avatars,
'databases' => $this->databases,
'tablesdb' => $this->tablesdb,
'locale' => $this->locale,
'health' => $this->health,
'project' => $this->project,
'storage' => $this->storage,
'teams' => $this->teams,
'users' => $this->users,
'vcs' => $this->vcs,
'sites' => $this->sites,
'functions' => $this->functions,
'proxy' => $this->proxy,
'graphql' => $this->graphql,
'migrations' => $this->migrations,
'messaging' => $this->messaging,
'createdAt' => $this->createdAt,
'updatedAt' => $this->updatedAt,
];
}
public static function getName(): string
{
return Resource::TYPE_SERVICES;
}
public function getGroup(): string
{
return Transfer::GROUP_SETTINGS;
}
public function getAccount(): bool
{
return $this->account;
}
public function getAvatars(): bool
{
return $this->avatars;
}
public function getDatabases(): bool
{
return $this->databases;
}
public function getTablesdb(): bool
{
return $this->tablesdb;
}
public function getLocale(): bool
{
return $this->locale;
}
public function getHealth(): bool
{
return $this->health;
}
public function getProject(): bool
{
return $this->project;
}
public function getStorage(): bool
{
return $this->storage;
}
public function getTeams(): bool
{
return $this->teams;
}
public function getUsers(): bool
{
return $this->users;
}
public function getVcs(): bool
{
return $this->vcs;
}
public function getSites(): bool
{
return $this->sites;
}
public function getFunctions(): bool
{
return $this->functions;
}
public function getProxy(): bool
{
return $this->proxy;
}
public function getGraphql(): bool
{
return $this->graphql;
}
public function getMigrations(): bool
{
return $this->migrations;
}
public function getMessaging(): bool
{
return $this->messaging;
}
}
+60
View File
@@ -66,6 +66,7 @@ use Utopia\Migration\Resources\Messaging\Topic;
use Utopia\Migration\Resources\Settings\Labels;
use Utopia\Migration\Resources\Settings\ProjectVariable;
use Utopia\Migration\Resources\Settings\Protocols;
use Utopia\Migration\Resources\Settings\Services as ServicesResource;
use Utopia\Migration\Resources\Settings\Webhook;
use Utopia\Migration\Resources\Sites\Deployment as SiteDeployment;
use Utopia\Migration\Resources\Sites\EnvVar as SiteEnvVar;
@@ -228,6 +229,7 @@ class Appwrite extends Source
Resource::TYPE_WEBHOOK,
Resource::TYPE_PROTOCOLS,
Resource::TYPE_LABELS,
Resource::TYPE_SERVICES,
];
}
@@ -1548,6 +1550,11 @@ class Appwrite extends Source
// Singleton — one labels array per project.
$report[Resource::TYPE_LABELS] = 1;
}
if (\in_array(Resource::TYPE_SERVICES, $resources)) {
// Singleton — one services config per project.
$report[Resource::TYPE_SERVICES] = 1;
}
}
/**
@@ -1611,6 +1618,59 @@ class Appwrite extends Source
previous: $e
));
}
try {
if (\in_array(Resource::TYPE_SERVICES, $resources)) {
$this->exportServices();
}
} catch (\Throwable $e) {
$this->addError(new Exception(
Resource::TYPE_SERVICES,
Transfer::GROUP_SETTINGS,
message: $e->getMessage(),
code: $e->getCode(),
previous: $e
));
}
}
/**
* Read service enable/disable flags from /v1/project. The response exposes
* them as `serviceStatusFor<Name>` keys; we collapse them into one Services
* resource carrying all 17 toggles.
*/
private function exportServices(): void
{
$response = $this->call('GET', '/v1/project');
if (!\is_array($response)) {
return;
}
$services = new ServicesResource(
$this->projectId,
(bool) ($response['serviceStatusForAccount'] ?? true),
(bool) ($response['serviceStatusForAvatars'] ?? true),
(bool) ($response['serviceStatusForDatabases'] ?? true),
(bool) ($response['serviceStatusForTablesdb'] ?? true),
(bool) ($response['serviceStatusForLocale'] ?? true),
(bool) ($response['serviceStatusForHealth'] ?? true),
(bool) ($response['serviceStatusForProject'] ?? true),
(bool) ($response['serviceStatusForStorage'] ?? true),
(bool) ($response['serviceStatusForTeams'] ?? true),
(bool) ($response['serviceStatusForUsers'] ?? true),
(bool) ($response['serviceStatusForVcs'] ?? true),
(bool) ($response['serviceStatusForSites'] ?? true),
(bool) ($response['serviceStatusForFunctions'] ?? true),
(bool) ($response['serviceStatusForProxy'] ?? true),
(bool) ($response['serviceStatusForGraphql'] ?? true),
(bool) ($response['serviceStatusForMigrations'] ?? true),
(bool) ($response['serviceStatusForMessaging'] ?? true),
createdAt: $response['$createdAt'] ?? '',
updatedAt: $response['$updatedAt'] ?? '',
);
$this->callback([$services]);
}
/**
+2
View File
@@ -100,6 +100,7 @@ class Transfer
Resource::TYPE_WEBHOOK,
Resource::TYPE_PROTOCOLS,
Resource::TYPE_LABELS,
Resource::TYPE_SERVICES,
];
public const GROUP_BACKUPS_RESOURCES = [
@@ -146,6 +147,7 @@ class Transfer
Resource::TYPE_WEBHOOK,
Resource::TYPE_PROTOCOLS,
Resource::TYPE_LABELS,
Resource::TYPE_SERVICES,
// legacy
Resource::TYPE_DOCUMENT,