Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Migration/Resources/Database/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function fromArray(array $array): self
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'] ?? '',
Expand Down
10 changes: 6 additions & 4 deletions src/Migration/Sources/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
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;
Expand Down Expand Up @@ -127,7 +127,7 @@ public function __construct(

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:
Expand Down Expand Up @@ -928,10 +928,12 @@ private function exportEntities(string $databaseName, int $batchSize): void

$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,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we only need rowSecurity

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need the documentsecurity as well -> it was missing earlier. Now here internally it will get replaced due to the fromArray. So passing both rowSecurity and documentSecurity.

'permissions' => $table['$permissions'],
'createdAt' => $table['$createdAt'],
'updatedAt' => $table['$updatedAt'],
Expand Down Expand Up @@ -1153,7 +1155,7 @@ private function exportRecords(string $entityName, string $fieldName, int $batch

unset($row['$id']);
unset($row['$permissions']);
unset($row['$collectionId']);
unset($row['$tableId']);
unset($row['$databaseId']);
unset($row['$sequence']);
unset($row['$collection']);
Comment thread
abnegate marked this conversation as resolved.
Expand Down
33 changes: 12 additions & 21 deletions src/Migration/Sources/Appwrite/Reader/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

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;
Expand All @@ -17,8 +16,7 @@
class API implements Reader
{
public function __construct(
private readonly Databases $database,
/* private readonly Tables $table, */
private readonly TablesDB $database,
) {
}

Expand Down Expand Up @@ -73,13 +71,12 @@ public function report(array $resources, array &$report, array $resourceIds = []
$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;
Expand Down Expand Up @@ -108,8 +105,7 @@ public function report(array $resources, array &$report, array $resourceIds = []
}

if (Resource::isSupported(Resource::TYPE_ROW, $resources)) {
/* $rowsResponse = $this->tables->listRows(...) */
$rowsResponse = $this->database->listDocuments(
$rowsResponse = $this->database->listRows(
$databaseId,
$tableId,
[Query::limit(1)]
Expand Down Expand Up @@ -137,11 +133,10 @@ public function listDatabases(array $queries = []): array
*/
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'];
}

/**
Expand All @@ -152,12 +147,11 @@ public function listTables(Database $resource, array $queries = []): array
*/
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'];
}

/**
Expand All @@ -168,7 +162,6 @@ public function listColumns(Table $resource, array $queries = []): array
*/
public function listIndexes(Table $resource, array $queries = []): array
{
/* $this->tables->listIndexes(...)['indexes'] */
return $this->database->listIndexes(
$resource->getDatabase()->getId(),
$resource->getId(),
Expand All @@ -185,12 +178,11 @@ public function listIndexes(Table $resource, array $queries = []): array
*/
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'];
}

/**
Expand All @@ -202,8 +194,7 @@ public function listRows(Table $resource, array $queries = []): array
*/
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,
Expand Down
Loading