From 2f7270734300d4f5ac450a9bb3d0e11b32986a53 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 18 May 2026 16:10:10 +0100 Subject: [PATCH] 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(). --- src/Migration/Destinations/Appwrite.php | 41 ++++ src/Migration/Resource.php | 2 + src/Migration/Resources/Settings/Services.php | 194 ++++++++++++++++++ src/Migration/Sources/Appwrite.php | 60 ++++++ src/Migration/Transfer.php | 2 + 5 files changed, 299 insertions(+) create mode 100644 src/Migration/Resources/Settings/Services.php diff --git a/src/Migration/Destinations/Appwrite.php b/src/Migration/Destinations/Appwrite.php index df1817c8d6..a40ae2c48b 100644 --- a/src/Migration/Destinations/Appwrite.php +++ b/src/Migration/Destinations/Appwrite.php @@ -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', [ diff --git a/src/Migration/Resource.php b/src/Migration/Resource.php index ddbed66718..a77ceaa90c 100644 --- a/src/Migration/Resource.php +++ b/src/Migration/Resource.php @@ -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, diff --git a/src/Migration/Resources/Settings/Services.php b/src/Migration/Resources/Settings/Services.php new file mode 100644 index 0000000000..3b7474c468 --- /dev/null +++ b/src/Migration/Resources/Settings/Services.php @@ -0,0 +1,194 @@ +id = $id; + $this->createdAt = $createdAt; + $this->updatedAt = $updatedAt; + } + + /** + * @param array $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 + */ + 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; + } +} diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index e166a6e54b..9d0c265c1f 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -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` 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]); } /** diff --git a/src/Migration/Transfer.php b/src/Migration/Transfer.php index 1e096efced..7bc80502fc 100644 --- a/src/Migration/Transfer.php +++ b/src/Migration/Transfer.php @@ -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,