Skip to content

Commit 111f622

Browse files
authored
Merge pull request #170 from utopia-php/db-migration-api-issue
updated to TablesDB
2 parents 9726690 + edc9021 commit 111f622

File tree

3 files changed

+20
-26
lines changed

3 files changed

+20
-26
lines changed

src/Migration/Resources/Database/Table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static function fromArray(array $array): self
5353
Database::fromArray($array['database']),
5454
name: $array['name'],
5555
id: $array['id'],
56-
rowSecurity: $array['rowSecurity'] ?? $array['documentSecurity'],
56+
rowSecurity: (bool) ($array['rowSecurity'] ?? $array['documentSecurity'] ?? false),
5757
permissions: $array['permissions'] ?? [],
5858
createdAt: $array['createdAt'] ?? '',
5959
updatedAt: $array['updatedAt'] ?? '',

src/Migration/Sources/Appwrite.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
use Appwrite\AppwriteException;
66
use Appwrite\Client;
77
use Appwrite\Query;
8-
use Appwrite\Services\Databases;
98
use Appwrite\Services\Functions;
109
use Appwrite\Services\Messaging;
1110
use Appwrite\Services\Sites;
1211
use Appwrite\Services\Storage;
12+
use Appwrite\Services\TablesDB;
1313
use Appwrite\Services\Teams;
1414
use Appwrite\Services\Users;
1515
use Utopia\Database\Database as UtopiaDatabase;
@@ -127,7 +127,7 @@ public function __construct(
127127

128128
switch ($this->source) {
129129
case static::SOURCE_API:
130-
$this->reader = new APIReader(new Databases($this->client));
130+
$this->reader = new APIReader(new TablesDB($this->client));
131131
break;
132132

133133
case static::SOURCE_DATABASE:
@@ -928,10 +928,12 @@ private function exportEntities(string $databaseName, int $batchSize): void
928928

929929
$response = $this->reader->listTables($database, $queries);
930930
foreach ($response as $table) {
931+
$rowSecurity = $table['rowSecurity'] ?? $table['documentSecurity'] ?? false;
931932
$newTable = self::getEntity($databaseName, [
932933
'id' => $table['$id'],
933934
'name' => $table['name'],
934-
'documentSecurity' => $table['documentSecurity'],
935+
'rowSecurity' => $rowSecurity,
936+
'documentSecurity' => $rowSecurity,
935937
'permissions' => $table['$permissions'],
936938
'createdAt' => $table['$createdAt'],
937939
'updatedAt' => $table['$updatedAt'],
@@ -1153,10 +1155,11 @@ private function exportRecords(string $entityName, string $fieldName, int $batch
11531155

11541156
unset($row['$id']);
11551157
unset($row['$permissions']);
1156-
unset($row['$collectionId']);
11571158
unset($row['$databaseId']);
11581159
unset($row['$sequence']);
11591160
unset($row['$collection']);
1161+
unset($row['$tableId']);
1162+
unset($row['$table']);
11601163

11611164
$row = self::getRecord($table->getDatabase()->getType(), [
11621165
'id' => $id,

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

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
use Appwrite\AppwriteException;
66
use Appwrite\Query;
7-
use Appwrite\Services\Databases;
8-
/* use Appwrite\Services\Tables; */
7+
use Appwrite\Services\TablesDB;
98
use Utopia\Migration\Resource;
109
use Utopia\Migration\Resources\Database\Database;
1110
use Utopia\Migration\Resources\Database\Table;
@@ -17,8 +16,7 @@
1716
class API implements Reader
1817
{
1918
public function __construct(
20-
private readonly Databases $database,
21-
/* private readonly Tables $table, */
19+
private readonly TablesDB $database,
2220
) {
2321
}
2422

@@ -73,13 +71,12 @@ public function report(array $resources, array &$report, array $resourceIds = []
7371
$lastTable = null;
7472

7573
while (true) {
76-
/* $currentTables = $this->tables->list(...); */
77-
$currentTables = $this->database->listCollections(
74+
$currentTables = $this->database->listTables(
7875
$databaseId,
7976
$lastTable
8077
? [Query::cursorAfter($lastTable)]
8178
: [Query::limit($pageLimit)]
82-
)['collections']; /* ['tables'] */
79+
)['tables'];
8380

8481
$tables = \array_merge($tables, $currentTables);
8582
$lastTable = $tables[count($tables) - 1]['$id'] ?? null;
@@ -108,8 +105,7 @@ public function report(array $resources, array &$report, array $resourceIds = []
108105
}
109106

110107
if (Resource::isSupported(Resource::TYPE_ROW, $resources)) {
111-
/* $rowsResponse = $this->tables->listRows(...) */
112-
$rowsResponse = $this->database->listDocuments(
108+
$rowsResponse = $this->database->listRows(
113109
$databaseId,
114110
$tableId,
115111
[Query::limit(1)]
@@ -137,11 +133,10 @@ public function listDatabases(array $queries = []): array
137133
*/
138134
public function listTables(Database $resource, array $queries = []): array
139135
{
140-
/* $this->tables->list(...)['tables'] */
141-
return $this->database->listCollections(
136+
return $this->database->listTables(
142137
$resource->getId(),
143138
$queries
144-
)['collections'];
139+
)['tables'];
145140
}
146141

147142
/**
@@ -152,12 +147,11 @@ public function listTables(Database $resource, array $queries = []): array
152147
*/
153148
public function listColumns(Table $resource, array $queries = []): array
154149
{
155-
/* $this->tables->listColumns(...)['columns'] */
156-
return $this->database->listAttributes(
150+
return $this->database->listColumns(
157151
$resource->getDatabase()->getId(),
158152
$resource->getId(),
159153
$queries
160-
)['attributes'];
154+
)['columns'];
161155
}
162156

163157
/**
@@ -168,7 +162,6 @@ public function listColumns(Table $resource, array $queries = []): array
168162
*/
169163
public function listIndexes(Table $resource, array $queries = []): array
170164
{
171-
/* $this->tables->listIndexes(...)['indexes'] */
172165
return $this->database->listIndexes(
173166
$resource->getDatabase()->getId(),
174167
$resource->getId(),
@@ -185,12 +178,11 @@ public function listIndexes(Table $resource, array $queries = []): array
185178
*/
186179
public function listRows(Table $resource, array $queries = []): array
187180
{
188-
/* $this->tables->listRows(...)['rows'] */
189-
return $this->database->listDocuments(
181+
return $this->database->listRows(
190182
$resource->getDatabase()->getId(),
191183
$resource->getId(),
192184
$queries
193-
)['documents'];
185+
)['rows'];
194186
}
195187

196188
/**
@@ -202,8 +194,7 @@ public function listRows(Table $resource, array $queries = []): array
202194
*/
203195
public function getRow(Table $resource, string $rowId, array $queries = []): array
204196
{
205-
/* $this->tables->getRow(...) */
206-
return $this->database->getDocument(
197+
return $this->database->getRow(
207198
$resource->getDatabase()->getId(),
208199
$resource->getId(),
209200
$rowId,

0 commit comments

Comments
 (0)