Skip to content

Commit 3583aac

Browse files
committed
feat: add messaging resource migration support
1 parent c2d0169 commit 3583aac

16 files changed

Lines changed: 1340 additions & 0 deletions

File tree

src/Migration/Destinations/Appwrite.php

Lines changed: 404 additions & 0 deletions
Large diffs are not rendered by default.

src/Migration/Destinations/Local.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ public static function getSupportedResources(): array
7070
Resource::TYPE_FUNCTION,
7171
Resource::TYPE_DEPLOYMENT,
7272
Resource::TYPE_ENVIRONMENT_VARIABLE,
73+
74+
// Messaging
75+
Resource::TYPE_PROVIDER,
76+
Resource::TYPE_TOPIC,
77+
Resource::TYPE_SUBSCRIBER,
78+
Resource::TYPE_MESSAGE,
7379
];
7480
}
7581

src/Migration/Resource.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ abstract class Resource implements \JsonSerializable
4646

4747
public const TYPE_INDEX = 'index';
4848

49+
public const TYPE_PROVIDER = 'provider';
50+
51+
public const TYPE_TOPIC = 'topic';
52+
4953
// Children (Resources that are created by other resources)
5054

5155
public const TYPE_COLUMN = 'column';
@@ -60,6 +64,10 @@ abstract class Resource implements \JsonSerializable
6064

6165
public const TYPE_ENVIRONMENT_VARIABLE = 'environment-variable';
6266

67+
public const TYPE_SUBSCRIBER = 'subscriber';
68+
69+
public const TYPE_MESSAGE = 'message';
70+
6371
// legacy terminologies
6472
public const TYPE_DOCUMENT = 'document';
6573
public const TYPE_ATTRIBUTE = 'attribute';
@@ -89,6 +97,10 @@ abstract class Resource implements \JsonSerializable
8997
self::TYPE_ENVIRONMENT_VARIABLE,
9098
self::TYPE_TEAM,
9199
self::TYPE_MEMBERSHIP,
100+
self::TYPE_PROVIDER,
101+
self::TYPE_TOPIC,
102+
self::TYPE_SUBSCRIBER,
103+
self::TYPE_MESSAGE,
92104

93105
// legacy
94106
self::TYPE_DOCUMENT,
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<?php
2+
3+
namespace Utopia\Migration\Resources\Messaging;
4+
5+
use Utopia\Migration\Resource;
6+
use Utopia\Migration\Transfer;
7+
8+
class Message extends Resource
9+
{
10+
/**
11+
* @param string $id
12+
* @param string $providerType
13+
* @param array<string> $topics
14+
* @param array<string> $users
15+
* @param array<string> $targets
16+
* @param array<string, mixed> $data
17+
* @param string $messageStatus
18+
* @param string $scheduledAt
19+
* @param string $deliveredAt
20+
* @param array<string> $deliveryErrors
21+
* @param int $deliveredTotal
22+
* @param array<string, string> $targetUserMap Source target ID => source user ID mapping for ID resolution
23+
*/
24+
public function __construct(
25+
string $id,
26+
private readonly string $providerType,
27+
private readonly array $topics = [],
28+
private readonly array $users = [],
29+
private readonly array $targets = [],
30+
private readonly array $data = [],
31+
private readonly string $messageStatus = '',
32+
private readonly string $scheduledAt = '',
33+
private readonly string $deliveredAt = '',
34+
private readonly array $deliveryErrors = [],
35+
private readonly int $deliveredTotal = 0,
36+
private readonly array $targetUserMap = [],
37+
protected string $createdAt = '',
38+
protected string $updatedAt = '',
39+
) {
40+
$this->id = $id;
41+
}
42+
43+
/**
44+
* @param array<string, mixed> $array
45+
* @return self
46+
*/
47+
public static function fromArray(array $array): self
48+
{
49+
return new self(
50+
$array['id'],
51+
$array['providerType'] ?? '',
52+
$array['topics'] ?? [],
53+
$array['users'] ?? [],
54+
$array['targets'] ?? [],
55+
$array['data'] ?? [],
56+
$array['messageStatus'] ?? $array['status'] ?? '',
57+
$array['scheduledAt'] ?? '',
58+
$array['deliveredAt'] ?? '',
59+
$array['deliveryErrors'] ?? [],
60+
$array['deliveredTotal'] ?? 0,
61+
$array['targetUserMap'] ?? [],
62+
$array['createdAt'] ?? '',
63+
$array['updatedAt'] ?? '',
64+
);
65+
}
66+
67+
/**
68+
* @return array<string, mixed>
69+
*/
70+
public function jsonSerialize(): array
71+
{
72+
return [
73+
'id' => $this->id,
74+
'providerType' => $this->providerType,
75+
'topics' => $this->topics,
76+
'users' => $this->users,
77+
'targets' => $this->targets,
78+
'data' => $this->data,
79+
'messageStatus' => $this->messageStatus,
80+
'scheduledAt' => $this->scheduledAt,
81+
'deliveredAt' => $this->deliveredAt,
82+
'deliveryErrors' => $this->deliveryErrors,
83+
'deliveredTotal' => $this->deliveredTotal,
84+
'targetUserMap' => $this->targetUserMap,
85+
'createdAt' => $this->createdAt,
86+
'updatedAt' => $this->updatedAt,
87+
];
88+
}
89+
90+
public static function getName(): string
91+
{
92+
return Resource::TYPE_MESSAGE;
93+
}
94+
95+
public function getGroup(): string
96+
{
97+
return Transfer::GROUP_MESSAGING;
98+
}
99+
100+
public function getProviderType(): string
101+
{
102+
return $this->providerType;
103+
}
104+
105+
/**
106+
* @return array<string>
107+
*/
108+
public function getTopics(): array
109+
{
110+
return $this->topics;
111+
}
112+
113+
/**
114+
* @return array<string>
115+
*/
116+
public function getUsers(): array
117+
{
118+
return $this->users;
119+
}
120+
121+
/**
122+
* @return array<string>
123+
*/
124+
public function getTargets(): array
125+
{
126+
return $this->targets;
127+
}
128+
129+
/**
130+
* @return array<string, mixed>
131+
*/
132+
public function getData(): array
133+
{
134+
return $this->data;
135+
}
136+
137+
public function getMessageStatus(): string
138+
{
139+
return $this->messageStatus;
140+
}
141+
142+
public function getScheduledAt(): string
143+
{
144+
return $this->scheduledAt;
145+
}
146+
147+
public function getDeliveredAt(): string
148+
{
149+
return $this->deliveredAt;
150+
}
151+
152+
/**
153+
* @return array<string>
154+
*/
155+
public function getDeliveryErrors(): array
156+
{
157+
return $this->deliveryErrors;
158+
}
159+
160+
public function getDeliveredTotal(): int
161+
{
162+
return $this->deliveredTotal;
163+
}
164+
165+
/**
166+
* @return array<string, string>
167+
*/
168+
public function getTargetUserMap(): array
169+
{
170+
return $this->targetUserMap;
171+
}
172+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
namespace Utopia\Migration\Resources\Messaging;
4+
5+
use Utopia\Migration\Resource;
6+
use Utopia\Migration\Transfer;
7+
8+
class Provider extends Resource
9+
{
10+
/**
11+
* @param string $id
12+
* @param string $name
13+
* @param string $provider
14+
* @param string $type
15+
* @param bool $enabled
16+
* @param array<string, mixed> $credentials
17+
* @param array<string, mixed> $options
18+
*/
19+
public function __construct(
20+
string $id,
21+
private readonly string $name,
22+
private readonly string $provider,
23+
private readonly string $type,
24+
private readonly bool $enabled = true,
25+
private readonly array $credentials = [],
26+
private readonly array $options = [],
27+
protected string $createdAt = '',
28+
protected string $updatedAt = '',
29+
) {
30+
$this->id = $id;
31+
}
32+
33+
/**
34+
* @param array<string, mixed> $array
35+
* @return self
36+
*/
37+
public static function fromArray(array $array): self
38+
{
39+
return new self(
40+
$array['id'],
41+
$array['name'] ?? '',
42+
$array['provider'] ?? '',
43+
$array['type'] ?? '',
44+
$array['enabled'] ?? true,
45+
$array['credentials'] ?? [],
46+
$array['options'] ?? [],
47+
$array['createdAt'] ?? '',
48+
$array['updatedAt'] ?? '',
49+
);
50+
}
51+
52+
/**
53+
* @return array<string, mixed>
54+
*/
55+
public function jsonSerialize(): array
56+
{
57+
return [
58+
'id' => $this->id,
59+
'name' => $this->name,
60+
'provider' => $this->provider,
61+
'type' => $this->type,
62+
'enabled' => $this->enabled,
63+
'credentials' => $this->credentials,
64+
'options' => $this->options,
65+
'createdAt' => $this->createdAt,
66+
'updatedAt' => $this->updatedAt,
67+
];
68+
}
69+
70+
public static function getName(): string
71+
{
72+
return Resource::TYPE_PROVIDER;
73+
}
74+
75+
public function getGroup(): string
76+
{
77+
return Transfer::GROUP_MESSAGING;
78+
}
79+
80+
public function getProviderName(): string
81+
{
82+
return $this->name;
83+
}
84+
85+
public function getProvider(): string
86+
{
87+
return $this->provider;
88+
}
89+
90+
public function getType(): string
91+
{
92+
return $this->type;
93+
}
94+
95+
public function getEnabled(): bool
96+
{
97+
return $this->enabled;
98+
}
99+
100+
/**
101+
* @return array<string, mixed>
102+
*/
103+
public function getCredentials(): array
104+
{
105+
return $this->credentials;
106+
}
107+
108+
/**
109+
* @return array<string, mixed>
110+
*/
111+
public function getOptions(): array
112+
{
113+
return $this->options;
114+
}
115+
}

0 commit comments

Comments
 (0)