From 8108e0bf7fa379415ededc3b99c34e1307ba8ff9 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 21 Apr 2026 17:12:46 +0530 Subject: [PATCH 1/5] updated to TablesDB --- src/Migration/Sources/Appwrite.php | 4 +-- src/Migration/Sources/Appwrite/Reader/API.php | 33 +++++++------------ 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index e5e57fa90d..355e40c1e7 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -5,11 +5,11 @@ namespace Utopia\Migration\Sources; use Appwrite\AppwriteException; use Appwrite\Client; use Appwrite\Query; -use Appwrite\Services\Databases; use Appwrite\Services\Functions; use Appwrite\Services\Messaging; use Appwrite\Services\Sites; use Appwrite\Services\Storage; +use Appwrite\Services\TablesDB; use Appwrite\Services\Teams; use Appwrite\Services\Users; use Utopia\Database\Database as UtopiaDatabase; @@ -127,7 +127,7 @@ class Appwrite extends Source switch ($this->source) { case static::SOURCE_API: - $this->reader = new APIReader(new Databases($this->client)); + $this->reader = new APIReader(new TablesDB($this->client)); break; case static::SOURCE_DATABASE: diff --git a/src/Migration/Sources/Appwrite/Reader/API.php b/src/Migration/Sources/Appwrite/Reader/API.php index b42835bd70..47a52f9dc6 100644 --- a/src/Migration/Sources/Appwrite/Reader/API.php +++ b/src/Migration/Sources/Appwrite/Reader/API.php @@ -4,8 +4,7 @@ namespace Utopia\Migration\Sources\Appwrite\Reader; use Appwrite\AppwriteException; use Appwrite\Query; -use Appwrite\Services\Databases; -/* use Appwrite\Services\Tables; */ +use Appwrite\Services\TablesDB; use Utopia\Migration\Resource; use Utopia\Migration\Resources\Database\Database; use Utopia\Migration\Resources\Database\Table; @@ -17,8 +16,7 @@ use Utopia\Migration\Sources\Appwrite\Reader; class API implements Reader { public function __construct( - private readonly Databases $database, - /* private readonly Tables $table, */ + private readonly TablesDB $database, ) { } @@ -73,13 +71,12 @@ class API implements Reader $lastTable = null; while (true) { - /* $currentTables = $this->tables->list(...); */ - $currentTables = $this->database->listCollections( + $currentTables = $this->database->listTables( $databaseId, $lastTable ? [Query::cursorAfter($lastTable)] : [Query::limit($pageLimit)] - )['collections']; /* ['tables'] */ + )['tables']; $tables = \array_merge($tables, $currentTables); $lastTable = $tables[count($tables) - 1]['$id'] ?? null; @@ -108,8 +105,7 @@ class API implements Reader } if (Resource::isSupported(Resource::TYPE_ROW, $resources)) { - /* $rowsResponse = $this->tables->listRows(...) */ - $rowsResponse = $this->database->listDocuments( + $rowsResponse = $this->database->listRows( $databaseId, $tableId, [Query::limit(1)] @@ -137,11 +133,10 @@ class API implements Reader */ public function listTables(Database $resource, array $queries = []): array { - /* $this->tables->list(...)['tables'] */ - return $this->database->listCollections( + return $this->database->listTables( $resource->getId(), $queries - )['collections']; + )['tables']; } /** @@ -152,12 +147,11 @@ class API implements Reader */ public function listColumns(Table $resource, array $queries = []): array { - /* $this->tables->listColumns(...)['columns'] */ - return $this->database->listAttributes( + return $this->database->listColumns( $resource->getDatabase()->getId(), $resource->getId(), $queries - )['attributes']; + )['columns']; } /** @@ -168,7 +162,6 @@ class API implements Reader */ public function listIndexes(Table $resource, array $queries = []): array { - /* $this->tables->listIndexes(...)['indexes'] */ return $this->database->listIndexes( $resource->getDatabase()->getId(), $resource->getId(), @@ -185,12 +178,11 @@ class API implements Reader */ public function listRows(Table $resource, array $queries = []): array { - /* $this->tables->listRows(...)['rows'] */ - return $this->database->listDocuments( + return $this->database->listRows( $resource->getDatabase()->getId(), $resource->getId(), $queries - )['documents']; + )['rows']; } /** @@ -202,8 +194,7 @@ class API implements Reader */ public function getRow(Table $resource, string $rowId, array $queries = []): array { - /* $this->tables->getRow(...) */ - return $this->database->getDocument( + return $this->database->getRow( $resource->getDatabase()->getId(), $resource->getId(), $rowId, From f3f8baca833475563d2437ad9df1f5cbd3f7fab2 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 21 Apr 2026 17:32:13 +0530 Subject: [PATCH 2/5] updated --- src/Migration/Resources/Database/Table.php | 2 +- src/Migration/Sources/Appwrite.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Migration/Resources/Database/Table.php b/src/Migration/Resources/Database/Table.php index 889d90fe1f..0ba04a5cda 100644 --- a/src/Migration/Resources/Database/Table.php +++ b/src/Migration/Resources/Database/Table.php @@ -53,7 +53,7 @@ class Table extends Resource Database::fromArray($array['database']), name: $array['name'], id: $array['id'], - rowSecurity: $array['rowSecurity'] ?? $array['documentSecurity'], + rowSecurity: (bool) ($array['rowSecurity'] ?? $array['documentSecurity'] ?? false), permissions: $array['permissions'] ?? [], createdAt: $array['createdAt'] ?? '', updatedAt: $array['updatedAt'] ?? '', diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index 355e40c1e7..6691c6a8ba 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -928,10 +928,12 @@ class Appwrite extends Source $response = $this->reader->listTables($database, $queries); foreach ($response as $table) { + $rowSecurity = $table['rowSecurity'] ?? $table['documentSecurity'] ?? false; $newTable = self::getEntity($databaseName, [ 'id' => $table['$id'], 'name' => $table['name'], - 'documentSecurity' => $table['documentSecurity'], + 'rowSecurity' => $rowSecurity, + 'documentSecurity' => $rowSecurity, 'permissions' => $table['$permissions'], 'createdAt' => $table['$createdAt'], 'updatedAt' => $table['$updatedAt'], From d8ad759751d5d089c4dc9378dff12a00eba1bfd5 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 21 Apr 2026 17:57:41 +0530 Subject: [PATCH 3/5] updated --- src/Migration/Sources/Appwrite.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index 6691c6a8ba..e5eedaab81 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -1153,9 +1153,16 @@ class Appwrite extends Source $id = $row['$id']; $permissions = $row['$permissions']; + // TablesDB(API reader) returns `$tableId`, while downstream import cleanup still + // normalizes/removes legacy `$collectionId`. Mirror the value to keep + // compatibility across both shapes. + if (isset($row['$tableId']) && !isset($row['$collectionId'])) { + $row['$collectionId'] = $row['$tableId']; + } + unset($row['$id']); unset($row['$permissions']); - unset($row['$collectionId']); + unset($row['$tableId']); unset($row['$databaseId']); unset($row['$sequence']); unset($row['$collection']); From 325ea937951780192458db8d5a168140f2f4e4b0 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 21 Apr 2026 18:06:54 +0530 Subject: [PATCH 4/5] updated --- src/Migration/Sources/Appwrite.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index e5eedaab81..e21f9b23a2 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -1153,13 +1153,6 @@ class Appwrite extends Source $id = $row['$id']; $permissions = $row['$permissions']; - // TablesDB(API reader) returns `$tableId`, while downstream import cleanup still - // normalizes/removes legacy `$collectionId`. Mirror the value to keep - // compatibility across both shapes. - if (isset($row['$tableId']) && !isset($row['$collectionId'])) { - $row['$collectionId'] = $row['$tableId']; - } - unset($row['$id']); unset($row['$permissions']); unset($row['$tableId']); From edc90215ae5ab669562d735a9bfed39abf9bf80b Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 21 Apr 2026 18:20:37 +0530 Subject: [PATCH 5/5] updated --- src/Migration/Sources/Appwrite.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Migration/Sources/Appwrite.php b/src/Migration/Sources/Appwrite.php index e21f9b23a2..daf9b6a3f3 100644 --- a/src/Migration/Sources/Appwrite.php +++ b/src/Migration/Sources/Appwrite.php @@ -1155,10 +1155,11 @@ class Appwrite extends Source unset($row['$id']); unset($row['$permissions']); - unset($row['$tableId']); unset($row['$databaseId']); unset($row['$sequence']); unset($row['$collection']); + unset($row['$tableId']); + unset($row['$table']); $row = self::getRecord($table->getDatabase()->getType(), [ 'id' => $id,