Skip to content
Open

Joins #133

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
1d86a6b
Migration
fogelito Dec 22, 2025
ae04b11
Migration
fogelito Dec 22, 2025
98dd145
select
fogelito Dec 22, 2025
01e06cf
fallback query select
fogelito Dec 23, 2025
6a95abb
4.5.2
fogelito Jan 15, 2026
f2c5f6a
Merge branch 'main' of https://github.com/utopia-php/migration into j…
fogelito Jan 15, 2026
53ce92c
pull main
fogelito Jan 15, 2026
67c8eda
Merge branch 'main' of https://github.com/utopia-php/migration into j…
fogelito Jan 18, 2026
69ade1c
Update lock
fogelito Jan 18, 2026
066bd70
lock
fogelito Jan 18, 2026
49bddeb
database 4.5.2
fogelito Jan 18, 2026
f50c5ad
fix many2many
fogelito Jan 18, 2026
805bdb8
append queries
fogelito Jan 18, 2026
317e4c9
DB 4.6.2
fogelito Jan 28, 2026
bfafb18
lock
fogelito Jan 28, 2026
525ba8c
lock
fogelito Jan 28, 2026
bc73611
Merge branch 'main' of https://github.com/utopia-php/migration into j…
fogelito Jan 28, 2026
fb8378a
lock
fogelito Jan 28, 2026
fd6b9bc
SDK original
fogelito Jan 28, 2026
4030ff3
database 5.0
fogelito Feb 2, 2026
daa5f17
Merge branch 'main' of https://github.com/utopia-php/migration into j…
fogelito Feb 8, 2026
0a632aa
Update main
fogelito Feb 8, 2026
d115b61
Fix codeQL
fogelito Feb 8, 2026
9aeb2d5
Merge branch 'main' of https://github.com/utopia-php/migration into j…
fogelito Feb 11, 2026
ac60b6d
update main
fogelito Feb 11, 2026
4582154
Merge branch 'main' of https://github.com/utopia-php/migration into j…
fogelito Feb 18, 2026
db744ef
Update database 5.3.1
fogelito Feb 18, 2026
6817db3
Merge branch 'main' of https://github.com/utopia-php/migration into j…
fogelito Mar 2, 2026
b1c5095
Update lock
fogelito Mar 2, 2026
63df4dd
Merge branch 'main' of https://github.com/utopia-php/migration into j…
fogelito Mar 18, 2026
3a33326
database subquery
fogelito Mar 19, 2026
e60685a
Merge branch 'main' of https://github.com/utopia-php/migration into j…
fogelito Mar 19, 2026
7b1750f
database subqueries + update
fogelito Mar 19, 2026
19feff6
Fix this reader
fogelito Mar 23, 2026
b41b305
Fix this reader
fogelito Mar 23, 2026
32da357
Merge branch 'main' of https://github.com/utopia-php/migration into j…
fogelito Apr 6, 2026
c030a2a
pull main
fogelito Apr 6, 2026
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",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Development branch dependency must be replaced before merge

The utopia-php/database dependency is pointing to dev-joins8 as 5.3.1, a development branch alias. This is not suitable for merging to main — the branch may be unstable, subject to breaking changes, or may be deleted. The dependency should be updated to a stable release constraint (e.g. 5.*) once the dev-joins8 changes are merged and tagged upstream.

Suggested change
"utopia-php/database": "dev-joins8 as 5.3.1",
"utopia-php/database": "5.*",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Indentation inconsistency

This line uses leading spaces instead of the 8-space indentation consistent with the surrounding lines in composer.json. All other require entries use a consistent 8-space indent.

Suggested change
"utopia-php/database": "dev-joins8 as 5.3.1",
"utopia-php/database": "dev-joins8 as 5.3.1",

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

"utopia-php/storage": "1.0.*",
"utopia-php/dsn": "0.2.*",
"halaxa/json-machine": "^1.2"
Expand Down
288 changes: 126 additions & 162 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/Migration/Destinations/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ protected function createEntity(Table $resource): bool
'search' => implode(' ', [$resource->getId(), $resource->getTableName()]),
'$createdAt' => $createdAt,
'$updatedAt' => $updatedAt,
'attributes' => null,
'indexes' => null,
]));

$resource->setSequence($table->getSequence());
Expand Down
1 change: 1 addition & 0 deletions src/Migration/Resources/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function __construct(
* updatedAt: string,
* enabled: bool,
* originalId: string|null,
* type: string|null,
* database: string
* } $array
*/
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 @@ -1100,6 +1100,11 @@ private function exportRecords(string $entityName, string $fieldName, int $batch
}

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

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

$manyToMany = [];

if ($this->reader->getSupportForAttributes()) {
Expand All @@ -1118,22 +1123,22 @@ private function exportRecords(string $entityName, string $fieldName, int $batch
}
}

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

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

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

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

$rowItem = $this->reader->getRow(
$table,
$row['$id'],
[$this->reader->querySelect($stack)]
$queries
);
Comment on lines +1131 to 1142
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 $queries variable shadowing makes the code fragile

Inside the foreach ($response as $row) loop, $queries is reassigned to a new empty array for the getRow() call, silently overwriting the outer $queries that was built for listRows() (with limit, cursor, and select clauses). While the outer while (true) loop re-initialises $queries at the top of each page, any future change inside this block could accidentally corrupt pagination state. Consider using a distinct variable name:

Suggested change
$queries = [];
$queries[] = $this->reader->querySelect('$id'); // Adding $id because we can't select only relations
foreach ($manyToMany as $relation) {
$stack[] = $relation . '.$id';
$queries[] = $this->reader->querySelect($relation . '.$id');
}
$rowItem = $this->reader->getRow(
$table,
$row['$id'],
[$this->reader->querySelect($stack)]
$queries
);
$joinQueries = [];
$joinQueries[] = $this->reader->querySelect('$id'); // Adding $id because we can't select only relations
foreach ($manyToMany as $relation) {
$joinQueries[] = $this->reader->querySelect($relation . '.$id');
}
$rowItem = $this->reader->getRow(
$table,
$row['$id'],
$joinQueries
);


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 @@ -414,12 +414,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);
}
Comment on lines 421 to 423
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Query::select() expects an array, not a bare string

Utopia\Database\Query::select() expects an array of attribute names. Passing the column string directly (without wrapping it in an array) is inconsistent with the API.php reader which correctly uses Query::select([$column]). Passing a bare string may result in incorrect query construction or a type error at runtime.

Suggested change
{
return Query::select($columns);
return Query::select($column);
}
public function querySelect(string $column): Query
{
return Query::select([$column]);
}


/**
Expand Down
Loading