Skip to content

Commit cd3fb87

Browse files
committed
Merge remote-tracking branch 'origin/add-policies-migration' into add-smtp-migration
2 parents 0d7e56a + 7c55885 commit cd3fb87

16 files changed

Lines changed: 129 additions & 283 deletions

File tree

src/Migration/Destinations/Appwrite.php

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Appwrite\Enums\Framework;
1111
use Appwrite\Enums\PasswordHash;
1212
use Appwrite\Enums\ProjectProtocolId;
13-
use Appwrite\Enums\ProjectServiceId;
1413
use Appwrite\Enums\Runtime;
1514
use Appwrite\Enums\SmtpEncryption;
1615
use Appwrite\InputFile;
@@ -292,13 +291,13 @@ public static function getSupportedResources(): array
292291
// Integrations
293292
Resource::TYPE_PLATFORM,
294293
Resource::TYPE_API_KEY,
294+
Resource::TYPE_WEBHOOK,
295295

296-
// Settings
296+
// Project
297297
Resource::TYPE_PROJECT_VARIABLE,
298-
Resource::TYPE_WEBHOOK,
299-
Resource::TYPE_PROTOCOLS,
300-
Resource::TYPE_LABELS,
301-
Resource::TYPE_SERVICES,
298+
Resource::TYPE_PROJECT_PROTOCOLS,
299+
Resource::TYPE_PROJECT_LABELS,
300+
Resource::TYPE_PROJECT_SERVICES,
302301
Resource::TYPE_SMTP,
303302

304303
// Backups
@@ -461,7 +460,7 @@ protected function import(array $resources, callable $callback): void
461460
Transfer::GROUP_SITES => $this->importSiteResource($resource),
462461
Transfer::GROUP_INTEGRATIONS => $this->importIntegrationsResource($resource),
463462
Transfer::GROUP_BACKUPS => $this->importBackupResource($resource),
464-
Transfer::GROUP_SETTINGS => $this->importSettingsResource($resource),
463+
Transfer::GROUP_PROJECTS => $this->importProjectsResource($resource),
465464
default => throw new \Exception('Invalid resource group', Exception::CODE_VALIDATION),
466465
};
467466
} catch (\Throwable $e) {
@@ -3112,6 +3111,10 @@ public function importIntegrationsResource(Resource $resource): Resource
31123111
/** @var ApiKey $resource */
31133112
$this->createApiKey($resource);
31143113
break;
3114+
case Resource::TYPE_WEBHOOK:
3115+
/** @var Webhook $resource */
3116+
$this->createWebhook($resource);
3117+
break;
31153118
}
31163119

31173120
if ($resource->getStatus() !== Resource::STATUS_SKIPPED) {
@@ -3121,26 +3124,22 @@ public function importIntegrationsResource(Resource $resource): Resource
31213124
return $resource;
31223125
}
31233126

3124-
public function importSettingsResource(Resource $resource): Resource
3127+
public function importProjectsResource(Resource $resource): Resource
31253128
{
31263129
switch ($resource->getName()) {
31273130
case Resource::TYPE_PROJECT_VARIABLE:
31283131
/** @var ProjectVariable $resource */
31293132
$this->createProjectVariable($resource);
31303133
break;
3131-
case Resource::TYPE_WEBHOOK:
3132-
/** @var Webhook $resource */
3133-
$this->createWebhook($resource);
3134-
break;
3135-
case Resource::TYPE_PROTOCOLS:
3134+
case Resource::TYPE_PROJECT_PROTOCOLS:
31363135
/** @var Protocols $resource */
31373136
$this->createProtocols($resource);
31383137
break;
3139-
case Resource::TYPE_LABELS:
3138+
case Resource::TYPE_PROJECT_LABELS:
31403139
/** @var Labels $resource */
31413140
$this->createLabels($resource);
31423141
break;
3143-
case Resource::TYPE_SERVICES:
3142+
case Resource::TYPE_PROJECT_SERVICES:
31443143
/** @var ServicesResource $resource */
31453144
$this->createServices($resource);
31463145
break;
@@ -3236,23 +3235,9 @@ protected function createServices(ServicesResource $resource): bool
32363235
$project = $this->dbForPlatform->getDocument('projects', $this->projectId);
32373236
$services = $project->getAttribute('services', []);
32383237

3239-
$services[(string) ProjectServiceId::ACCOUNT()] = $resource->getAccount();
3240-
$services[(string) ProjectServiceId::AVATARS()] = $resource->getAvatars();
3241-
$services[(string) ProjectServiceId::DATABASES()] = $resource->getDatabases();
3242-
$services[(string) ProjectServiceId::TABLESDB()] = $resource->getTablesdb();
3243-
$services[(string) ProjectServiceId::LOCALE()] = $resource->getLocale();
3244-
$services[(string) ProjectServiceId::HEALTH()] = $resource->getHealth();
3245-
$services[(string) ProjectServiceId::PROJECT()] = $resource->getProject();
3246-
$services[(string) ProjectServiceId::STORAGE()] = $resource->getStorage();
3247-
$services[(string) ProjectServiceId::TEAMS()] = $resource->getTeams();
3248-
$services[(string) ProjectServiceId::USERS()] = $resource->getUsers();
3249-
$services[(string) ProjectServiceId::VCS()] = $resource->getVcs();
3250-
$services[(string) ProjectServiceId::SITES()] = $resource->getSites();
3251-
$services[(string) ProjectServiceId::FUNCTIONS()] = $resource->getFunctions();
3252-
$services[(string) ProjectServiceId::PROXY()] = $resource->getProxy();
3253-
$services[(string) ProjectServiceId::GRAPHQL()] = $resource->getGraphql();
3254-
$services[(string) ProjectServiceId::MIGRATIONS()] = $resource->getMigrations();
3255-
$services[(string) ProjectServiceId::MESSAGING()] = $resource->getMessaging();
3238+
foreach ($resource->getServices() as $serviceId => $enabled) {
3239+
$services[$serviceId] = (bool) $enabled;
3240+
}
32563241

32573242
$this->dbForPlatform->getAuthorization()->skip(fn () => $this->dbForPlatform->updateDocument(
32583243
'projects',

src/Migration/Resource.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ abstract class Resource implements \JsonSerializable
7878
// Integrations
7979
public const TYPE_PLATFORM = 'platform';
8080
public const TYPE_API_KEY = 'api-key';
81-
82-
// Settings
83-
public const TYPE_PROJECT_VARIABLE = 'project-variable';
8481
public const TYPE_WEBHOOK = 'webhook';
85-
public const TYPE_PROTOCOLS = 'protocols';
86-
public const TYPE_LABELS = 'labels';
87-
public const TYPE_SERVICES = 'services';
8882
public const TYPE_SMTP = 'smtp';
8983

84+
// Project (per-project singleton/settings resources)
85+
public const TYPE_PROJECT_VARIABLE = 'project-variable';
86+
public const TYPE_PROJECT_PROTOCOLS = 'project-protocols';
87+
public const TYPE_PROJECT_LABELS = 'project-labels';
88+
public const TYPE_PROJECT_SERVICES = 'project-services';
89+
9090
// Messaging
9191
public const TYPE_SUBSCRIBER = 'subscriber';
9292
public const TYPE_MESSAGE = 'message';
@@ -129,12 +129,12 @@ abstract class Resource implements \JsonSerializable
129129
self::TYPE_POLICIES,
130130
self::TYPE_PLATFORM,
131131
self::TYPE_API_KEY,
132-
self::TYPE_PROJECT_VARIABLE,
133132
self::TYPE_WEBHOOK,
134-
self::TYPE_PROTOCOLS,
135-
self::TYPE_LABELS,
136-
self::TYPE_SERVICES,
137133
self::TYPE_SMTP,
134+
self::TYPE_PROJECT_VARIABLE,
135+
self::TYPE_PROJECT_PROTOCOLS,
136+
self::TYPE_PROJECT_LABELS,
137+
self::TYPE_PROJECT_SERVICES,
138138
self::TYPE_PROVIDER,
139139
self::TYPE_TOPIC,
140140
self::TYPE_SUBSCRIBER,

src/Migration/Resources/Settings/Labels.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ public function jsonSerialize(): array
5454

5555
public static function getName(): string
5656
{
57-
return Resource::TYPE_LABELS;
57+
return Resource::TYPE_PROJECT_LABELS;
5858
}
5959

6060
public function getGroup(): string
6161
{
62-
return Transfer::GROUP_SETTINGS;
62+
return Transfer::GROUP_PROJECTS;
6363
}
6464

6565
/**

src/Migration/Resources/Settings/ProjectVariable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static function getName(): string
5858

5959
public function getGroup(): string
6060
{
61-
return Transfer::GROUP_SETTINGS;
61+
return Transfer::GROUP_PROJECTS;
6262
}
6363

6464
public function getKey(): string

src/Migration/Resources/Settings/Protocols.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ public function jsonSerialize(): array
5757

5858
public static function getName(): string
5959
{
60-
return Resource::TYPE_PROTOCOLS;
60+
return Resource::TYPE_PROJECT_PROTOCOLS;
6161
}
6262

6363
public function getGroup(): string
6464
{
65-
return Transfer::GROUP_SETTINGS;
65+
return Transfer::GROUP_PROJECTS;
6666
}
6767

6868
public function getRest(): bool

src/Migration/Resources/Settings/SMTP.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public static function getName(): string
7979

8080
public function getGroup(): string
8181
{
82-
return Transfer::GROUP_SETTINGS;
82+
return Transfer::GROUP_PROJECTS;
8383
}
8484

8585
public function getEnabled(): bool

src/Migration/Resources/Settings/Services.php

Lines changed: 16 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,18 @@
66
use Utopia\Migration\Transfer;
77

88
/**
9-
* Singleton settings resource carrying the project's 17 per-service
10-
* enable/disable flags. One per project; destination flips each via
11-
* Project::updateService().
9+
* Singleton settings resource carrying the project's per-service enable/disable
10+
* flags, keyed by ServiceId value. One per project; destination merges each
11+
* entry into the project's services map.
1212
*/
1313
class Services extends Resource
1414
{
15+
/**
16+
* @param array<string, bool> $services Map of ServiceId string → enabled flag.
17+
*/
1518
public function __construct(
1619
string $id,
17-
private readonly bool $account = true,
18-
private readonly bool $avatars = true,
19-
private readonly bool $databases = true,
20-
private readonly bool $tablesdb = true,
21-
private readonly bool $locale = true,
22-
private readonly bool $health = true,
23-
private readonly bool $project = true,
24-
private readonly bool $storage = true,
25-
private readonly bool $teams = true,
26-
private readonly bool $users = true,
27-
private readonly bool $vcs = true,
28-
private readonly bool $sites = true,
29-
private readonly bool $functions = true,
30-
private readonly bool $proxy = true,
31-
private readonly bool $graphql = true,
32-
private readonly bool $migrations = true,
33-
private readonly bool $messaging = true,
20+
private readonly array $services = [],
3421
string $createdAt = '',
3522
string $updatedAt = '',
3623
) {
@@ -46,23 +33,7 @@ public static function fromArray(array $array): self
4633
{
4734
return new self(
4835
$array['id'],
49-
(bool) ($array['account'] ?? true),
50-
(bool) ($array['avatars'] ?? true),
51-
(bool) ($array['databases'] ?? true),
52-
(bool) ($array['tablesdb'] ?? true),
53-
(bool) ($array['locale'] ?? true),
54-
(bool) ($array['health'] ?? true),
55-
(bool) ($array['project'] ?? true),
56-
(bool) ($array['storage'] ?? true),
57-
(bool) ($array['teams'] ?? true),
58-
(bool) ($array['users'] ?? true),
59-
(bool) ($array['vcs'] ?? true),
60-
(bool) ($array['sites'] ?? true),
61-
(bool) ($array['functions'] ?? true),
62-
(bool) ($array['proxy'] ?? true),
63-
(bool) ($array['graphql'] ?? true),
64-
(bool) ($array['migrations'] ?? true),
65-
(bool) ($array['messaging'] ?? true),
36+
(array) ($array['services'] ?? []),
6637
createdAt: $array['createdAt'] ?? '',
6738
updatedAt: $array['updatedAt'] ?? '',
6839
);
@@ -75,120 +46,27 @@ public function jsonSerialize(): array
7546
{
7647
return [
7748
'id' => $this->id,
78-
'account' => $this->account,
79-
'avatars' => $this->avatars,
80-
'databases' => $this->databases,
81-
'tablesdb' => $this->tablesdb,
82-
'locale' => $this->locale,
83-
'health' => $this->health,
84-
'project' => $this->project,
85-
'storage' => $this->storage,
86-
'teams' => $this->teams,
87-
'users' => $this->users,
88-
'vcs' => $this->vcs,
89-
'sites' => $this->sites,
90-
'functions' => $this->functions,
91-
'proxy' => $this->proxy,
92-
'graphql' => $this->graphql,
93-
'migrations' => $this->migrations,
94-
'messaging' => $this->messaging,
49+
'services' => $this->services,
9550
'createdAt' => $this->createdAt,
9651
'updatedAt' => $this->updatedAt,
9752
];
9853
}
9954

10055
public static function getName(): string
10156
{
102-
return Resource::TYPE_SERVICES;
57+
return Resource::TYPE_PROJECT_SERVICES;
10358
}
10459

10560
public function getGroup(): string
10661
{
107-
return Transfer::GROUP_SETTINGS;
108-
}
109-
110-
public function getAccount(): bool
111-
{
112-
return $this->account;
113-
}
114-
115-
public function getAvatars(): bool
116-
{
117-
return $this->avatars;
118-
}
119-
120-
public function getDatabases(): bool
121-
{
122-
return $this->databases;
123-
}
124-
125-
public function getTablesdb(): bool
126-
{
127-
return $this->tablesdb;
128-
}
129-
130-
public function getLocale(): bool
131-
{
132-
return $this->locale;
133-
}
134-
135-
public function getHealth(): bool
136-
{
137-
return $this->health;
138-
}
139-
140-
public function getProject(): bool
141-
{
142-
return $this->project;
143-
}
144-
145-
public function getStorage(): bool
146-
{
147-
return $this->storage;
62+
return Transfer::GROUP_PROJECTS;
14863
}
14964

150-
public function getTeams(): bool
151-
{
152-
return $this->teams;
153-
}
154-
155-
public function getUsers(): bool
156-
{
157-
return $this->users;
158-
}
159-
160-
public function getVcs(): bool
161-
{
162-
return $this->vcs;
163-
}
164-
165-
public function getSites(): bool
166-
{
167-
return $this->sites;
168-
}
169-
170-
public function getFunctions(): bool
171-
{
172-
return $this->functions;
173-
}
174-
175-
public function getProxy(): bool
176-
{
177-
return $this->proxy;
178-
}
179-
180-
public function getGraphql(): bool
181-
{
182-
return $this->graphql;
183-
}
184-
185-
public function getMigrations(): bool
186-
{
187-
return $this->migrations;
188-
}
189-
190-
public function getMessaging(): bool
65+
/**
66+
* @return array<string, bool>
67+
*/
68+
public function getServices(): array
19169
{
192-
return $this->messaging;
70+
return $this->services;
19371
}
19472
}

src/Migration/Resources/Settings/Webhook.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static function getName(): string
7373

7474
public function getGroup(): string
7575
{
76-
return Transfer::GROUP_SETTINGS;
76+
return Transfer::GROUP_INTEGRATIONS;
7777
}
7878

7979
public function getWebhookName(): string

0 commit comments

Comments
 (0)