Skip to content
Open

Joins #133

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"ext-curl": "*",
"ext-openssl": "*",
"appwrite/appwrite": "19.*",
"utopia-php/database": "5.*",
"utopia-php/database": "dev-joins8 as 5.3.1",
"utopia-php/storage": "1.0.*",
"utopia-php/dsn": "0.2.*",
"halaxa/json-machine": "^1.2"
Expand Down
53 changes: 31 additions & 22 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Migration/Resources/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function __construct(
* updatedAt: string,
* enabled: bool,
* originalId: string|null,
* type: string|null,
* } $array
*/
public static function fromArray(array $array): self
Expand Down
15 changes: 10 additions & 5 deletions src/Migration/Sources/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,11 @@ private function exportRows(int $batchSize): void
}

$selects = ['*', '$id', '$permissions', '$updatedAt', '$createdAt']; // We want relations flat!

foreach ($selects as $select) {
$queries[] = $this->database->querySelect($select);
}

$manyToMany = [];

$attributes = $this->cache->get(Column::getName());
Expand All @@ -1275,22 +1280,22 @@ private function exportRows(int $batchSize): void
}
/** @var Column|Relationship $attribute */

$queries[] = $this->database->querySelect($selects);

$response = $this->database->listRows($table, $queries);

foreach ($response as $row) {
// HACK: Handle many to many
if (!empty($manyToMany)) {
$stack = ['$id']; // Adding $id because we can't select only relations
$queries = [];
$queries[] = $this->database->querySelect('$id'); // Adding $id because we can't select only relations

foreach ($manyToMany as $relation) {
$stack[] = $relation . '.$id';
$queries[] = $this->database->querySelect($relation . '.$id');
}

$rowItem = $this->database->getRow(
$table,
$row['$id'],
[$this->database->querySelect($stack)]
$queries
);

foreach ($manyToMany as $key) {
Expand Down
5 changes: 3 additions & 2 deletions src/Migration/Sources/Appwrite/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Utopia\Migration\Sources\Appwrite;

use Utopia\Database\Query;
use Utopia\Migration\Resource;
use Utopia\Migration\Resources\Database\Database;
use Utopia\Migration\Resources\Database\Table;
Expand Down Expand Up @@ -78,10 +79,10 @@ public function getRow(Table $resource, string $rowId, array $queries = []): arr
/**
* Return a query to select the given attributes
*
* @param array $columns
* @param string $column
* @return QueryType|string
*/
public function querySelect(array $columns): mixed;
public function querySelect(string $column): mixed;

/**
* Return a query to filter the given attributes
Expand Down
6 changes: 3 additions & 3 deletions src/Migration/Sources/Appwrite/Reader/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,12 @@ public function getRow(Table $resource, string $rowId, array $queries = []): arr
}

/**
* @param array $columns
* @param string $column
* @return string
*/
public function querySelect(array $columns): string
public function querySelect(string $column): string
{
return Query::select($columns);
return Query::select([$column]);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Migration/Sources/Appwrite/Reader/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,12 +360,12 @@ public function getRow(TableResource $resource, string $rowId, array $queries =
}

/**
* @param array $columns
* @param string $column
* @return Query
*/
public function querySelect(array $columns): Query
public function querySelect(string $column): Query
{
return Query::select($columns);
return Query::select($column);
}

/**
Expand Down