Skip to content

Commit b77e8c2

Browse files
* linting
1 parent e8faed3 commit b77e8c2

10 files changed

Lines changed: 107 additions & 21 deletions

File tree

src/Migration/Destinations/Appwrite.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,8 @@ protected function createEntity(Table $resource): bool
443443
*/
444444
protected function createField(Column $resource): bool
445445
{
446-
// Skip columns for documents DB (schemaless)
447-
if ($resource->getTable()->getDatabase()->getType() === 'documents') {
448-
$resource->setStatus(Resource::STATUS_SKIPPED, 'Columns not supported for documents database');
446+
if ($resource->getTable()->getDatabase()->getDatabase() === Resource::TYPE_DOCUMENTSDB_DATABASE) {
447+
$resource->setStatus(Resource::STATUS_SKIPPED, 'Columns not supported for DocumentsDB');
449448
return false;
450449
}
451450

src/Migration/Resource.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ abstract class Resource implements \JsonSerializable
9898
public const DATABASE_TYPE_RESOURCE_MAP = [
9999
self::TYPE_DATABASE => [
100100
'entity' => self::TYPE_TABLE,
101-
'fields' => self::TYPE_COLUMN,
102-
'records' => self::TYPE_ROW,
101+
'field' => self::TYPE_COLUMN,
102+
'record' => self::TYPE_ROW,
103103
],
104104
self::TYPE_DOCUMENTSDB_DATABASE => [
105105
'entity' => self::TYPE_COLLECTION,
106-
'records' => self::TYPE_DOCUMENT,
107-
'fields' => self::TYPE_ATTRIBUTE,
106+
'record' => self::TYPE_DOCUMENT,
107+
'field' => self::TYPE_ATTRIBUTE,
108108
],
109109
];
110110

src/Migration/Resources/Database/Collection.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,42 @@
22

33
namespace Utopia\Migration\Resources\Database;
44

5-
use Override;
65
use Utopia\Migration\Resource;
76

87
class Collection extends Table
98
{
10-
#[Override]
119
public static function getName(): string
1210
{
1311
return Resource::TYPE_COLLECTION;
1412
}
13+
14+
/**
15+
* @param array{
16+
* database: array{
17+
* id: string,
18+
* name: string,
19+
* },
20+
* name: string,
21+
* id: string,
22+
* documentSecurity?: bool,
23+
* rowSecurity?: bool,
24+
* permissions: ?array<string>,
25+
* createdAt: string,
26+
* updatedAt: string,
27+
* enabled: bool
28+
* } $array
29+
*/
30+
public static function fromArray(array $array): self
31+
{
32+
return new self(
33+
DocumentsDB::fromArray($array['database']),
34+
name: $array['name'],
35+
id: $array['id'],
36+
rowSecurity: $array['rowSecurity'] ?? $array['documentSecurity'],
37+
permissions: $array['permissions'] ?? [],
38+
createdAt: $array['createdAt'] ?? '',
39+
updatedAt: $array['updatedAt'] ?? '',
40+
enabled: $array['enabled'] ?? true,
41+
);
42+
}
1543
}

src/Migration/Resources/Database/Database.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(
4444
*/
4545
public static function fromArray(array $array): self
4646
{
47-
return new static(
47+
return new self(
4848
$array['id'],
4949
$array['name'],
5050
createdAt: $array['createdAt'] ?? '',

src/Migration/Resources/Database/Document.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,42 @@ public static function getName(): string
1010
{
1111
return Resource::TYPE_DOCUMENT;
1212
}
13+
14+
/**
15+
* @param array{
16+
* id: string,
17+
* collection?: array{
18+
* database: array{
19+
* id: string,
20+
* name: string,
21+
* },
22+
* name: string,
23+
* id: string,
24+
* documentSecurity: bool,
25+
* permissions: ?array<string>
26+
* },
27+
* table?: array{
28+
* database: array{
29+
* id: string,
30+
* name: string,
31+
* },
32+
* name: string,
33+
* id: string,
34+
* rowSecurity: bool,
35+
* permissions: ?array<string>
36+
* },
37+
* data: array<string, mixed>,
38+
* permissions: ?array<string>
39+
* } $array
40+
*/
41+
public static function fromArray(array $array): self
42+
{
43+
// keeping table and collection to have backward compat
44+
return new self(
45+
$array['id'],
46+
Collection::fromArray($array['table'] ?? $array['collection']),
47+
$array['data'],
48+
$array['permissions'] ?? []
49+
);
50+
}
1351
}

src/Migration/Resources/Database/DocumentsDB.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,29 @@ public static function getName(): string
1010
{
1111
return Resource::TYPE_DOCUMENTSDB_DATABASE;
1212
}
13+
14+
/**
15+
* @param array{
16+
* id: string,
17+
* name: string,
18+
* createdAt: string,
19+
* updatedAt: string,
20+
* enabled: bool,
21+
* originalId: string|null,
22+
* database: string
23+
* } $array
24+
*/
25+
public static function fromArray(array $array): self
26+
{
27+
return new self(
28+
$array['id'],
29+
$array['name'],
30+
createdAt: $array['createdAt'] ?? '',
31+
updatedAt: $array['updatedAt'] ?? '',
32+
enabled: $array['enabled'] ?? true,
33+
originalId: $array['originalId'] ?? '',
34+
type: $array['type'] ?? 'legacy',
35+
database: $array['database'] ?? 'legacy'
36+
);
37+
}
1338
}

src/Migration/Resources/Database/Row.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct(
5252
*/
5353
public static function fromArray(array $array): self
5454
{
55-
return new static(
55+
return new self(
5656
$array['id'],
5757
Table::fromArray($array['table'] ?? $array['collection']),
5858
$array['data'],

src/Migration/Resources/Database/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct(
4949
*/
5050
public static function fromArray(array $array): self
5151
{
52-
return new static(
52+
return new self(
5353
Database::fromArray($array['database']),
5454
name: $array['name'],
5555
id: $array['id'],

src/Migration/Sources/Appwrite.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Appwrite\Services\Users;
1313
use Utopia\Database\Database as UtopiaDatabase;
1414
use Utopia\Database\DateTime as UtopiaDateTime;
15-
use Utopia\Database\Document as UtopiaDocument;
1615
use Utopia\Migration\Exception;
1716
use Utopia\Migration\Resource;
1817
use Utopia\Migration\Resources\Auth\Hash;
@@ -78,9 +77,9 @@ public function __construct(
7877
protected string $project,
7978
protected string $endpoint,
8079
protected string $key,
80+
callable $getDatabasesDB,
8181
protected string $source = self::SOURCE_API,
8282
protected ?UtopiaDatabase $dbForProject = null,
83-
callable $getDatabasesDB
8483
) {
8584
$this->client = (new Client())
8685
->setEndpoint($endpoint)
@@ -114,7 +113,6 @@ public static function getName(): string
114113
}
115114

116115
/**
117-
* Create a reader instance for general operations (not database-specific)
118116
*
119117
* @return Reader
120118
* @throws \Exception
@@ -734,7 +732,6 @@ private function exportDatabases(int $batchSize, array $resources = []): void
734732
/**
735733
* @param string $databaseName
736734
* @param int $batchSize
737-
* @param array<Resource> $databases
738735
* @throws Exception
739736
*/
740737
private function exportEntities(string $databaseName, int $batchSize): void
@@ -1694,7 +1691,6 @@ private function exportTablesDB(int $batchSize, array $resources)
16941691
*
16951692
* @param int $batchSize
16961693
* @param array $resources
1697-
* @param array $documentsDBDatabases
16981694
*/
16991695
private function exportDocumentsDB(int $batchSize, array $resources): void
17001696
{

src/Migration/Sources/Appwrite/Reader/Database.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,20 @@ public function report(array $resources, array &$report): mixed
126126
foreach ($tables as $table) {
127127
$tableSequence = $table->getSequence();
128128

129-
if (Resource::isSupported($databaseSpecificResources['records'], $resources)) {
129+
if (Resource::isSupported($databaseSpecificResources['record'], $resources)) {
130130
$rowTableId = "database_{$databaseSequence}_collection_{$tableSequence}";
131131
$count = $this->countResources($rowTableId, [], $dbResource);
132-
$report[$databaseSpecificResources['records']] += $count;
132+
$report[$databaseSpecificResources['record']] += $count;
133133
}
134134

135135
$commonQueries = [
136136
Query::equal('databaseInternalId', [$databaseSequence]),
137137
Query::equal('collectionInternalId', [$tableSequence]),
138138
];
139139

140-
if (Resource::isSupported($databaseSpecificResources['fields'], $resources)) {
140+
if (Resource::isSupported($databaseSpecificResources['field'], $resources)) {
141141
$count = $this->countResources('attributes', $commonQueries);
142-
$report[$databaseSpecificResources['fields']] += $count;
142+
$report[$databaseSpecificResources['field']] += $count;
143143
}
144144

145145
if (in_array(Resource::TYPE_INDEX, $resources)) {

0 commit comments

Comments
 (0)