mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Add Protocols migration
Singleton settings resource carrying REST/GraphQL/WebSocket flags. Source reads via raw GET /v1/project; destination flips each via Project::updateProtocol(). Lives in GROUP_SETTINGS.
This commit is contained in:
1 parent
5224e3ce9a
commit
d74e8cbd19
5 files changed
+158
No files matched your search
@@ -10,6 +10,7 @@ use Appwrite\Enums\BuildRuntime;
|
||||
use Appwrite\Enums\Compression;
|
||||
use Appwrite\Enums\Framework;
|
||||
use Appwrite\Enums\PasswordHash;
|
||||
use Appwrite\Enums\ProtocolId;
|
||||
use Appwrite\Enums\Runtime;
|
||||
use Appwrite\Enums\SmtpEncryption;
|
||||
use Appwrite\InputFile;
|
||||
@@ -60,6 +61,7 @@ use Utopia\Migration\Resources\Messaging\Provider;
|
||||
use Utopia\Migration\Resources\Messaging\Subscriber;
|
||||
use Utopia\Migration\Resources\Messaging\Topic;
|
||||
use Utopia\Migration\Resources\Settings\ProjectVariable;
|
||||
use Utopia\Migration\Resources\Settings\Protocols;
|
||||
use Utopia\Migration\Resources\Settings\Webhook;
|
||||
use Utopia\Migration\Resources\Sites\Deployment as SiteDeployment;
|
||||
use Utopia\Migration\Resources\Sites\EnvVar as SiteEnvVar;
|
||||
@@ -289,6 +291,7 @@ class Appwrite extends Destination
|
||||
// Settings
|
||||
Resource::TYPE_PROJECT_VARIABLE,
|
||||
Resource::TYPE_WEBHOOK,
|
||||
Resource::TYPE_PROTOCOLS,
|
||||
|
||||
// Backups
|
||||
Resource::TYPE_BACKUP_POLICY,
|
||||
@@ -3117,6 +3120,10 @@ class Appwrite extends Destination
|
||||
/** @var Webhook $resource */
|
||||
$this->createWebhook($resource);
|
||||
break;
|
||||
case Resource::TYPE_PROTOCOLS:
|
||||
/** @var Protocols $resource */
|
||||
$this->createProtocols($resource);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($resource->getStatus() !== Resource::STATUS_SKIPPED) {
|
||||
@@ -3165,6 +3172,26 @@ class Appwrite extends Destination
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flip each protocol on the destination via the SDK. Three single-field
|
||||
* updates rather than one bulk write — the SDK only exposes per-protocol
|
||||
* setters, mirroring upstream's per-flag controllers.
|
||||
*/
|
||||
protected function createProtocols(Protocols $resource): bool
|
||||
{
|
||||
$flags = [
|
||||
[ProtocolId::REST(), $resource->getRest()],
|
||||
[ProtocolId::GRAPHQL(), $resource->getGraphql()],
|
||||
[ProtocolId::WEBSOCKET(), $resource->getWebsocket()],
|
||||
];
|
||||
|
||||
foreach ($flags as [$protocol, $enabled]) {
|
||||
$this->project->updateProtocol($protocol, $enabled);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function createWebhook(Webhook $resource): bool
|
||||
{
|
||||
$existing = $this->dbForPlatform->findOne('webhooks', [
|
||||
|
||||
@@ -80,6 +80,7 @@ abstract class Resource implements \JsonSerializable
|
||||
// Settings
|
||||
public const TYPE_PROJECT_VARIABLE = 'project-variable';
|
||||
public const TYPE_WEBHOOK = 'webhook';
|
||||
public const TYPE_PROTOCOLS = 'protocols';
|
||||
|
||||
// Messaging
|
||||
public const TYPE_SUBSCRIBER = 'subscriber';
|
||||
@@ -124,6 +125,7 @@ abstract class Resource implements \JsonSerializable
|
||||
self::TYPE_API_KEY,
|
||||
self::TYPE_PROJECT_VARIABLE,
|
||||
self::TYPE_WEBHOOK,
|
||||
self::TYPE_PROTOCOLS,
|
||||
self::TYPE_PROVIDER,
|
||||
self::TYPE_TOPIC,
|
||||
self::TYPE_SUBSCRIBER,
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Utopia\Migration\Resources\Settings;
|
||||
|
||||
use Utopia\Migration\Resource;
|
||||
use Utopia\Migration\Transfer;
|
||||
|
||||
/**
|
||||
* Singleton resource representing the project's exposed API protocols
|
||||
* (REST, GraphQL, WebSocket). One per project; destination flips each
|
||||
* via Project::updateProtocol().
|
||||
*/
|
||||
class Protocols extends Resource
|
||||
{
|
||||
public function __construct(
|
||||
string $id,
|
||||
private readonly bool $rest = true,
|
||||
private readonly bool $graphql = true,
|
||||
private readonly bool $websocket = 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['rest'] ?? true),
|
||||
(bool) ($array['graphql'] ?? true),
|
||||
(bool) ($array['websocket'] ?? true),
|
||||
createdAt: $array['createdAt'] ?? '',
|
||||
updatedAt: $array['updatedAt'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'rest' => $this->rest,
|
||||
'graphql' => $this->graphql,
|
||||
'websocket' => $this->websocket,
|
||||
'createdAt' => $this->createdAt,
|
||||
'updatedAt' => $this->updatedAt,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getName(): string
|
||||
{
|
||||
return Resource::TYPE_PROTOCOLS;
|
||||
}
|
||||
|
||||
public function getGroup(): string
|
||||
{
|
||||
return Transfer::GROUP_SETTINGS;
|
||||
}
|
||||
|
||||
public function getRest(): bool
|
||||
{
|
||||
return $this->rest;
|
||||
}
|
||||
|
||||
public function getGraphql(): bool
|
||||
{
|
||||
return $this->graphql;
|
||||
}
|
||||
|
||||
public function getWebsocket(): bool
|
||||
{
|
||||
return $this->websocket;
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,7 @@ use Utopia\Migration\Resources\Messaging\Provider;
|
||||
use Utopia\Migration\Resources\Messaging\Subscriber;
|
||||
use Utopia\Migration\Resources\Messaging\Topic;
|
||||
use Utopia\Migration\Resources\Settings\ProjectVariable;
|
||||
use Utopia\Migration\Resources\Settings\Protocols;
|
||||
use Utopia\Migration\Resources\Settings\Webhook;
|
||||
use Utopia\Migration\Resources\Sites\Deployment as SiteDeployment;
|
||||
use Utopia\Migration\Resources\Sites\EnvVar as SiteEnvVar;
|
||||
@@ -224,6 +225,7 @@ class Appwrite extends Source
|
||||
// Settings
|
||||
Resource::TYPE_PROJECT_VARIABLE,
|
||||
Resource::TYPE_WEBHOOK,
|
||||
Resource::TYPE_PROTOCOLS,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1534,6 +1536,11 @@ class Appwrite extends Source
|
||||
$report[Resource::TYPE_WEBHOOK] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (\in_array(Resource::TYPE_PROTOCOLS, $resources)) {
|
||||
// Singleton — there is exactly one protocols config per project.
|
||||
$report[Resource::TYPE_PROTOCOLS] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1569,6 +1576,44 @@ class Appwrite extends Source
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if (\in_array(Resource::TYPE_PROTOCOLS, $resources)) {
|
||||
$this->exportProtocols();
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
$this->addError(new Exception(
|
||||
Resource::TYPE_PROTOCOLS,
|
||||
Transfer::GROUP_SETTINGS,
|
||||
message: $e->getMessage(),
|
||||
code: $e->getCode(),
|
||||
previous: $e
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read protocol flags from the source project document.
|
||||
* No SDK Project.get() exposed; using raw HTTP against /v1/project.
|
||||
*/
|
||||
private function exportProtocols(): void
|
||||
{
|
||||
$response = $this->call('GET', '/v1/project');
|
||||
|
||||
if (!\is_array($response)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$protocols = new Protocols(
|
||||
$this->projectId,
|
||||
(bool) ($response['protocolStatusForRest'] ?? true),
|
||||
(bool) ($response['protocolStatusForGraphql'] ?? true),
|
||||
(bool) ($response['protocolStatusForWebsocket'] ?? true),
|
||||
createdAt: $response['$createdAt'] ?? '',
|
||||
updatedAt: $response['$updatedAt'] ?? '',
|
||||
);
|
||||
|
||||
$this->callback([$protocols]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -98,6 +98,7 @@ class Transfer
|
||||
public const GROUP_SETTINGS_RESOURCES = [
|
||||
Resource::TYPE_PROJECT_VARIABLE,
|
||||
Resource::TYPE_WEBHOOK,
|
||||
Resource::TYPE_PROTOCOLS,
|
||||
];
|
||||
|
||||
public const GROUP_BACKUPS_RESOURCES = [
|
||||
@@ -142,6 +143,7 @@ class Transfer
|
||||
// Settings
|
||||
Resource::TYPE_PROJECT_VARIABLE,
|
||||
Resource::TYPE_WEBHOOK,
|
||||
Resource::TYPE_PROTOCOLS,
|
||||
|
||||
// legacy
|
||||
Resource::TYPE_DOCUMENT,
|
||||
|
||||
Reference in new issue
Block a user