Skip to content
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0e6ad57
partialUpdate
fogelito Jun 9, 2026
90e3634
update
fogelito Jun 10, 2026
4e56486
add collection
fogelito Jun 10, 2026
3d91101
Merge branch 'main' of github.com:utopia-php/database into partial-up…
fogelito Jun 10, 2026
8508d63
fix validation
fogelito Jun 10, 2026
6b2a7b5
remove unset
fogelito Jun 10, 2026
6d4db8d
fix perms
fogelito Jun 10, 2026
e29ee24
fix createdAt
fogelito Jun 10, 2026
f94cc01
(fix): CI — propagate partial-update semantics to SQLite/Postgres ada…
github-actions[bot] Jun 10, 2026
3a0c449
use clone
fogelito Jun 10, 2026
a879acd
Merge remote-tracking branch 'origin/partial-update' into partial-update
fogelito Jun 10, 2026
cec6e43
fix perms
fogelito Jun 10, 2026
a50e28f
Merge branch 'main' of github.com:utopia-php/database into partial-up…
fogelito Jun 10, 2026
76b2374
run
fogelito Jun 10, 2026
d14540d
revert
fogelito Jun 10, 2026
40d4b5c
revert
fogelito Jun 10, 2026
93e0eef
remove clone
fogelito Jun 10, 2026
5f0caca
Pstgres
fogelito Jun 10, 2026
5cda737
Pstgres
fogelito Jun 10, 2026
af4865c
Update
fogelito Jun 11, 2026
fcb8d7f
Update
fogelito Jun 11, 2026
71b7ae8
Update
fogelito Jun 11, 2026
359304b
Update
fogelito Jun 11, 2026
c869af2
Update
fogelito Jun 11, 2026
1e2110c
Update
fogelito Jun 11, 2026
e138860
Postgres adapter:
fogelito Jun 11, 2026
3037e58
Postgres adapter:
fogelito Jun 11, 2026
6ee688c
Update
fogelito Jun 11, 2026
08ab50f
Merge branch 'main' of github.com:utopia-php/database into partial-up…
fogelito Jun 11, 2026
f1dd93e
fix early return
fogelito Jun 11, 2026
1116d74
tests
fogelito Jun 16, 2026
1946dd5
Merge branch 'main' of github.com:utopia-php/database into partial-up…
fogelito Jun 16, 2026
5b6cbc5
Update main
fogelito Jun 16, 2026
5283655
tests
fogelito Jun 16, 2026
eeeec20
tests
fogelito Jun 16, 2026
9d4627e
Merge branch 'main' of github.com:utopia-php/database into partial-up…
fogelito Jun 18, 2026
38883ca
formatting
fogelito Jun 21, 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 phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
stopOnFailure="true"

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 stopOnFailure was flipped to true, which halts the entire suite on the first failure. Combined with the always-failing assertion in testPartialUpdateDocument, no tests after that point will execute, hiding the real pass/fail status of the rest of the suite. This should be reverted to false (the project's established default) before merging.

Suggested change
stopOnFailure="true"
stopOnFailure="false"

>
<testsuites>
<testsuite name="unit">
Expand Down
34 changes: 26 additions & 8 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -977,9 +977,23 @@ public function updateDocument(Document $collection, string $id, Document $docum
$spatialAttributes = $this->getSpatialAttributes($collection);
$collection = $collection->getId();
$attributes = $document->getAttributes();
$attributes['_createdAt'] = $document->getCreatedAt();
$attributes['_updatedAt'] = $document->getUpdatedAt();
$attributes['_permissions'] = json_encode($document->getPermissions());

if ($document->offsetExists('$updatedAt')) {
$attributes['_updatedAt'] = $document->getUpdatedAt();
}
if ($document->offsetExists('$createdAt')) {
$attributes['_createdAt'] = $document->getCreatedAt();
}
if ($document->offsetExists('$id')) {
$attributes['_uid'] = $document->getId();
}
if ($document->offsetExists('$permissions')) {
$attributes['_permissions'] = json_encode($document->getPermissions());
}

if (empty($attributes)) {
return $document;
}

$name = $this->filter($collection);
$columns = '';
Expand All @@ -998,7 +1012,8 @@ public function updateDocument(Document $collection, string $id, Document $docum
* Get current permissions from the database
*/
$sqlPermissions = $this->getPDO()->prepare($sql);
$sqlPermissions->bindValue(':_uid', $document->getId());

$sqlPermissions->bindValue(':_uid', $id);

if ($this->sharedTables) {
$sqlPermissions->bindValue(':_tenant', $this->tenant);
Expand Down Expand Up @@ -1071,7 +1086,7 @@ public function updateDocument(Document $collection, string $id, Document $docum
$removeQuery = $this->trigger(Database::EVENT_PERMISSIONS_DELETE, $removeQuery);

$stmtRemovePermissions = $this->getPDO()->prepare($removeQuery);
$stmtRemovePermissions->bindValue(':_uid', $document->getId());
$stmtRemovePermissions->bindValue(':_uid', $id);

if ($this->sharedTables) {
$stmtRemovePermissions->bindValue(':_tenant', $this->tenant);
Expand Down Expand Up @@ -1119,7 +1134,8 @@ public function updateDocument(Document $collection, string $id, Document $docum

$stmtAddPermissions = $this->getPDO()->prepare($sql);

$stmtAddPermissions->bindValue(":_uid", $document->getId());
$newUid = $document->offsetExists('$id') ? $document->getId() : $id;
$stmtAddPermissions->bindValue(":_uid", $newUid);

if ($this->sharedTables) {
$stmtAddPermissions->bindValue(":_tenant", $this->tenant);
Expand Down Expand Up @@ -1168,17 +1184,19 @@ public function updateDocument(Document $collection, string $id, Document $docum

$sql = "
UPDATE {$this->getSQLTable($name)}
SET {$columns} _uid = :_newUid
SET " . \rtrim($columns, ',') . "
WHERE _id=:_sequence
{$this->getTenantQuery($collection)}
";
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Comment thread
greptile-apps[bot] marked this conversation as resolved.

$sql = $this->trigger(Database::EVENT_DOCUMENT_UPDATE, $sql);

var_dump('============================================');
var_dump($sql);
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Outdated

$stmt = $this->getPDO()->prepare($sql);

$stmt->bindValue(':_sequence', $document->getSequence());
$stmt->bindValue(':_newUid', $document->getId());

if ($this->sharedTables) {
$stmt->bindValue(':_tenant', $this->tenant);
Expand Down
12 changes: 10 additions & 2 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -6137,8 +6137,10 @@ public function updateDocument(string $collection, string $id, Document $documen
}

$collection = $this->silent(fn () => $this->getCollection($collection));
$inputKeys = \array_keys($document->getArrayCopy());
$newUpdatedAt = $document->getUpdatedAt();
$document = $this->withTransaction(function () use ($collection, $id, $document, $newUpdatedAt) {

$document = $this->withTransaction(function () use ($collection, $id, $document, $newUpdatedAt, $inputKeys) {
$time = DateTime::now();
$old = $this->authorization->skip(fn () => $this->silent(
fn () => $this->getDocument($collection->getId(), $id, forUpdate: true)
Expand All @@ -6158,6 +6160,8 @@ public function updateDocument(string $collection, string $id, Document $documen

$skipPermissionsUpdate = ($originalPermissions === $currentPermissions);
}

var_dump($skipPermissionsUpdate);
$createdAt = $document->getCreatedAt();

$document = \array_merge($old->getArrayCopy(), $document->getArrayCopy());
Expand Down Expand Up @@ -6334,7 +6338,11 @@ public function updateDocument(string $collection, string $id, Document $documen

$document = $this->adapter->castingBefore($collection, $document);

$this->adapter->updateDocument($collection, $id, $document, $skipPermissionsUpdate);
$adapterDocument = new Document(\array_intersect_key($document->getArrayCopy(), \array_flip($inputKeys)));
$adapterDocument->setAttribute('$sequence', $old->getSequence());
$adapterDocument->setAttribute('$updatedAt', $document->getUpdatedAt());

$this->adapter->updateDocument($collection, $id, $adapterDocument, $skipPermissionsUpdate);

$document = $this->adapter->castingAfter($collection, $document);

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/Adapter/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

abstract class Base extends TestCase
{
use CollectionTests;
use CustomDocumentTypeTests;
// use CollectionTests;
// use CustomDocumentTypeTests;
use DocumentTests;
use AttributeTests;
use IndexTests;
Expand Down
40 changes: 39 additions & 1 deletion tests/e2e/Adapter/Scopes/DocumentTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -4645,7 +4645,45 @@ public function testEncodeDecode(): void
new Document(['$id' => '3', 'label' => 'z']),
], $result->getAttribute('tags'));
}
/**

public function testPartialUpdateDocument(): void
{
/** @var Database $database */
$database = $this->getDatabase();

$database->createCollection(__FUNCTION__);
$database->createAttribute(__FUNCTION__, 'string', Database::VAR_STRING, 128, true);

// Insert initial documents
$database->createDocument(__FUNCTION__, new Document([
'$id' => 'sam',
'string' => 'text📝 ' . $i,
]));

var_dump('=======================================================================================');
var_dump('=======================================================================================');

/**
* test Update $id
*/
$partial = new Document([
'$id'=> 'sam',
]);

$partial = $this->getDatabase()->updateDocument($document->getCollection(), $document->getId(), $partial);
var_dump($partial);
$this->assertEquals('sam', $partial->getId());


$partial = $this->getDatabase()->getDocument($document->getCollection(), $partial->getId());
var_dump($partial);
$this->assertEquals('sam', $partial->getId());
$this->assertEquals('text📝', $partial->getAttribute('string'));

$this->assertEquals('shmuel', 'fogel');
}
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Outdated

/**
* @depends testGetDocument
*/
public function testUpdateDocument(Document $document): Document
Expand Down
Loading