Skip to content

Commit 973a4da

Browse files
authored
Merge pull request #80 from utopia-php/swap-terminology
Swap terminologies
2 parents d528a45 + 7b819e9 commit 973a4da

33 files changed

Lines changed: 1289 additions & 1054 deletions

.env.example

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
1-
DESTINATION_APPWRITE_TEST_PROJECT=testProject
2-
DESTINATION_APPWRITE_TEST_ENDPOINT=http://localhost/v1
3-
DESTINATION_APPWRITE_TEST_KEY=xxxxxxxxxxxxxxxxxx
1+
# Providers
2+
SOURCE_PROVIDER=appwrite
3+
DESTINATION_PROVIDER=appwrite
4+
5+
# Appwrite (Database mode)
6+
SOURCE_APPWRITE_TEST_DSN=mysql:host=127.0.0.1;port=3306;dbname=appwrite
7+
SOURCE_APPWRITE_TEST_USER=user
8+
SOURCE_APPWRITE_TEST_PASSWORD=password
9+
SOURCE_APPWRITE_TEST_NAMESPACE=1
10+
11+
DESTINATION_APPWRITE_TEST_DSN=mysql:host=127.0.0.1;port=3306;dbname=appwrite
12+
DESTINATION_APPWRITE_TEST_USER=user
13+
DESTINATION_APPWRITE_TEST_PASSWORD=password
14+
DESTINATION_APPWRITE_TEST_NAMESPACE=2
415

16+
# Appwrite (API Key mode)
517
SOURCE_APPWRITE_TEST_PROJECT=testProject
618
SOURCE_APPWRITE_TEST_ENDPOINT=http://localhost/v1
719
SOURCE_APPWRITE_TEST_KEY=xxxxxxxxxxxxxxxxxx
820

21+
DESTINATION_APPWRITE_TEST_PROJECT=testProject
22+
DESTINATION_APPWRITE_TEST_ENDPOINT=http://localhost/v1
23+
DESTINATION_APPWRITE_TEST_KEY=xxxxxxxxxxxxxxxxxx
24+
25+
# Firebase
926
FIREBASE_TEST_PROJECT=testProject
1027
FIREBASE_TEST_ACCOUNT='{type: "service_account", ...}'
1128

29+
# Supabase
1230
SUPABASE_TEST_ENDPOINT=https://xxxxxxxxxxxx.supabase.co
1331
SUPABASE_TEST_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
1432
SUPABASE_TEST_HOST=db.xxxxxxxxxxxxxxxx.supabase.co
1533
SUPABASE_TEST_DATABASE=postgres
1634
SUPABASE_TEST_USERNAME=postgres
1735
SUPABASE_TEST_PASSWORD=xxxxxxxxxxxxxxxxxxxxx
1836

37+
# NHost
1938
NHOST_TEST_SUBDOMAIN=xxxxxxxxxxx
2039
NHOST_TEST_REGION=eu-central-1
2140
NHOST_TEST_SECRET=xxxxxxxxxxxxxxxxx

bin/MigrationCLI.php

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public function getSource(): Source
215215
$_ENV['SOURCE_APPWRITE_TEST_ENDPOINT'],
216216
$_ENV['SOURCE_APPWRITE_TEST_KEY'],
217217
Appwrite::SOURCE_DATABASE,
218-
$this->getDatabase(),
218+
$this->getDatabase('source'),
219219
);
220220
case 'supabase':
221221
return new Supabase(
@@ -252,7 +252,7 @@ public function getDestination(): Destination
252252
$_ENV['DESTINATION_APPWRITE_TEST_PROJECT'],
253253
$_ENV['DESTINATION_APPWRITE_TEST_ENDPOINT'],
254254
$_ENV['DESTINATION_APPWRITE_TEST_KEY'],
255-
$this->getDatabase(),
255+
$this->getDatabase('destination'),
256256
self::STRUCTURE
257257
);
258258
case 'local':
@@ -262,7 +262,7 @@ public function getDestination(): Destination
262262
}
263263
}
264264

265-
public function getDatabase(): Database
265+
public function getDatabase(string $type): Database
266266
{
267267
Database::addFilter(
268268
'subQueryAttributes',
@@ -277,12 +277,21 @@ function (mixed $value, Document $document, Database $database) {
277277
]);
278278

279279
foreach ($attributes as $attribute) {
280-
if ($attribute->getAttribute('type') === Database::VAR_RELATIONSHIP) {
281-
$options = $attribute->getAttribute('options');
282-
foreach ($options as $key => $value) {
283-
$attribute->setAttribute($key, $value);
284-
}
285-
$attribute->removeAttribute('options');
280+
$attributeType = $attribute->getAttribute('type');
281+
282+
switch ($attributeType) {
283+
case Database::VAR_RELATIONSHIP:
284+
$options = $attribute->getAttribute('options');
285+
foreach ($options as $key => $value) {
286+
$attribute->setAttribute($key, $value);
287+
}
288+
$attribute->removeAttribute('options');
289+
break;
290+
291+
case Database::VAR_STRING:
292+
$filters = $attribute->getAttribute('filters', []);
293+
$attribute->setAttribute('encrypt', in_array('encrypt', $filters));
294+
break;
286295
}
287296
}
288297

@@ -363,10 +372,16 @@ function (mixed $value, Document $attribute) {
363372
}
364373
);
365374

375+
$prefix = match ($type) {
376+
'source' => 'SOURCE_APPWRITE_TEST_',
377+
'destination' => 'DESTINATION_APPWRITE_TEST_',
378+
default => throw new Exception('Invalid type for database'),
379+
};
380+
366381
$database = new Database(new MariaDB(new PDO(
367-
$_ENV['DESTINATION_APPWRITE_TEST_DSN'],
368-
$_ENV['DESTINATION_APPWRITE_TEST_USER'],
369-
$_ENV['DESTINATION_APPWRITE_TEST_PASSWORD'],
382+
$_ENV[$prefix . 'DSN'],
383+
$_ENV[$prefix . 'USER'],
384+
$_ENV[$prefix . 'PASSWORD'],
370385
[
371386
PDO::ATTR_TIMEOUT => 3,
372387
PDO::ATTR_PERSISTENT => true,
@@ -378,7 +393,7 @@ function (mixed $value, Document $attribute) {
378393

379394
$database
380395
->setDatabase('appwrite')
381-
->setNamespace('_' . $_ENV['DESTINATION_APPWRITE_TEST_NAMESPACE']);
396+
->setNamespace('_' . $_ENV[$prefix . 'NAMESPACE']);
382397

383398
return $database;
384399
}

src/Migration/Cache.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public function add(Resource $resource): void
3939
$resource->setSequence(uniqid());
4040
}
4141

42-
if ($resource->getName() == Resource::TYPE_DOCUMENT) {
42+
if ($resource->getName() == Resource::TYPE_ROW || $resource->getName() == Resource::TYPE_DOCUMENT) {
4343
$status = $resource->getStatus();
44-
$documentId = $resource->getSequence();
45-
$this->cache[$resource->getName()][$documentId] = $status;
44+
$rowId = $resource->getSequence();
45+
$this->cache[$resource->getName()][$rowId] = $status;
4646
return;
4747
}
4848

@@ -78,14 +78,14 @@ public function addAll(array $resources): void
7878
*/
7979
public function update(Resource $resource): void
8080
{
81-
// if documents then updating the status counter only
82-
if ($resource->getName() == Resource::TYPE_DOCUMENT) {
83-
$documentId = $resource->getSequence();
84-
if (!isset($this->cache[$resource->getName()][$documentId])) {
81+
// if rows then updating the status counter only
82+
if ($resource->getName() == Resource::TYPE_ROW || $resource->getName() == Resource::TYPE_DOCUMENT) {
83+
$rowId = $resource->getSequence();
84+
if (!isset($this->cache[$resource->getName()][$rowId])) {
8585
$this->add($resource);
8686
} else {
8787
$status = $resource->getStatus();
88-
$this->cache[$resource->getName()][$documentId] = $status;
88+
$this->cache[$resource->getName()][$rowId] = $status;
8989
}
9090
return;
9191
}
@@ -119,7 +119,7 @@ public function updateAll(array $resources): void
119119
*/
120120
public function remove(Resource $resource): void
121121
{
122-
if ($resource->getName() === Resource::TYPE_DOCUMENT) {
122+
if ($resource->getName() == Resource::TYPE_ROW || $resource->getName() == Resource::TYPE_DOCUMENT) {
123123
if (! isset($this->cache[$resource->getName()][$resource->getSequence()])) {
124124
throw new \Exception('Resource does not exist in cache');
125125
}

0 commit comments

Comments
 (0)