-
Notifications
You must be signed in to change notification settings - Fork 55
Added new internal attributes $createdBy and$ updatedBy #680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f77eb9a
484d045
1bf9fb8
28a979e
8a85666
a6789e3
2a4805e
67791d1
6e40e79
5e17969
1140b58
c20f225
e706390
2cd4666
731fea0
f4a449b
e95802f
bd8a8ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -408,6 +408,14 @@ public function getDocument(Document $collection, string $id, array $queries = [ | |
| $document['$updatedAt'] = $document['_updatedAt']; | ||
| unset($document['_updatedAt']); | ||
| } | ||
| if (\array_key_exists('_createdBy', $document)) { | ||
| $document['$createdBy'] = $document['_createdBy']; | ||
| unset($document['_createdBy']); | ||
| } | ||
| if (\array_key_exists('_updatedBy', $document)) { | ||
| $document['$updatedBy'] = $document['_updatedBy']; | ||
| unset($document['_updatedBy']); | ||
| } | ||
| if (\array_key_exists('_permissions', $document)) { | ||
| $document['$permissions'] = json_decode($document['_permissions'] ?? '[]', true); | ||
| unset($document['_permissions']); | ||
|
|
@@ -468,6 +476,14 @@ public function updateDocuments(Document $collection, Document $updates, array $ | |
| $attributes['_createdAt'] = $updates->getCreatedAt(); | ||
| } | ||
|
|
||
| if (!empty($updates->getCreatedBy())) { | ||
| $attributes['_createdBy'] = $updates->getCreatedBy(); | ||
| } | ||
|
|
||
| if (!empty($updates->getUpdatedBy())) { | ||
| $attributes['_updatedBy'] = $updates->getUpdatedBy(); | ||
| } | ||
ArnabChatterjee20k marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if ($updates->offsetExists('$permissions')) { | ||
| $attributes['_permissions'] = json_encode($updates->getPermissions()); | ||
| } | ||
|
|
@@ -1053,10 +1069,12 @@ public function getAttributeWidth(Document $collection): int | |
| * `_tenant` int => 4 bytes | ||
| * `_createdAt` datetime(3) => 7 bytes | ||
| * `_updatedAt` datetime(3) => 7 bytes | ||
| * `_createdBy` varchar(255) => 1021 (4 * 255 + 1) bytes | ||
| * `_updatedBy` varchar(255) => 1021 (4 * 255 + 1) bytes | ||
| * `_permissions` mediumtext => 20 | ||
| */ | ||
|
|
||
| $total = 1067; | ||
| $total = 3109; | ||
|
|
||
| $attributes = $collection->getAttributes()['attributes']; | ||
|
|
||
|
|
@@ -1892,6 +1910,8 @@ protected function getAttributeProjection(array $selections, string $prefix): st | |
| '$permissions', | ||
| '$createdAt', | ||
| '$updatedAt', | ||
| '$createdBy', | ||
| '$updatedBy' | ||
| ]; | ||
|
|
||
| $selections = \array_diff($selections, [...$internalKeys, '$collection']); | ||
|
|
@@ -1919,6 +1939,8 @@ protected function getInternalKeyForAttribute(string $attribute): string | |
| '$tenant' => '_tenant', | ||
| '$createdAt' => '_createdAt', | ||
| '$updatedAt' => '_updatedAt', | ||
| '$createdBy' => '_createdBy', | ||
| '$updatedBy' => '_updatedBy', | ||
| '$permissions' => '_permissions', | ||
| default => $attribute | ||
| }; | ||
|
|
@@ -2013,6 +2035,8 @@ public function createDocuments(Document $collection, array $documents): array | |
| $attributes['_createdAt'] = $document->getCreatedAt(); | ||
| $attributes['_updatedAt'] = $document->getUpdatedAt(); | ||
| $attributes['_permissions'] = \json_encode($document->getPermissions()); | ||
| $attributes['_createdBy'] = $document->getCreatedBy(); | ||
| $attributes['_updatedBy'] = $document->getUpdatedBy(); | ||
|
|
||
| if (!empty($document->getSequence())) { | ||
| $attributes['_id'] = $document->getSequence(); | ||
|
|
@@ -2127,6 +2151,8 @@ public function upsertDocuments( | |
| $attributes['_uid'] = $document->getId(); | ||
| $attributes['_createdAt'] = $document->getCreatedAt(); | ||
| $attributes['_updatedAt'] = $document->getUpdatedAt(); | ||
| $attributes['_createdBy'] = $document->getCreatedBy(); | ||
| $attributes['_updatedBy'] = $document->getUpdatedBy(); | ||
| $attributes['_permissions'] = \json_encode($document->getPermissions()); | ||
|
Comment on lines
+2154
to
2156
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainUpsert path sets auditing fields: verify adapter update clause Attributes include 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "PWD: $(pwd)"
echo "---- locate SQL.php ----"
rg -n --hidden --no-ignore -S "src/Database/Adapter/SQL.php" || true
echo "---- show SQL.php 2130-2200 ----"
if [ -f src/Database/Adapter/SQL.php ]; then
sed -n '2130,2200p' src/Database/Adapter/SQL.php || true
else
echo "src/Database/Adapter/SQL.php not found"
fi
echo "---- search for getUpsertStatement definitions ----"
rg -n --hidden --no-ignore -S "function\s+getUpsertStatement" || true
echo "---- search for class MariaDB ----"
rg -n --hidden --no-ignore -S "class\s+MariaDB" || true
echo "---- show any MariaDB file contents around getUpsertStatement if found ----"
for f in $(rg -n --hidden --no-ignore -S "class\s+MariaDB" -g '!vendor' --files-with-matches || true); do
echo "---- $f ----"
sed -n '1,240p' "$f" || true
done
echo "---- search for _updatedBy/_createdBy usages ----"
rg -n --hidden --no-ignore -S "_updatedBy|_createdBy" || true
echo "---- search for ON DUPLICATE KEY UPDATE / upsert occurrences ----"
rg -n --hidden --no-ignore -S "ON DUPLICATE KEY UPDATE|ON CONFLICT|\\bupsert\\b" || trueLength of output: 9672 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "PWD: $(pwd)"
echo "---- show MariaDB.php 1100-1320 ----"
if [ -f src/Database/Adapter/MariaDB.php ]; then
sed -n '1100,1320p' src/Database/Adapter/MariaDB.php || true
else
echo "src/Database/Adapter/MariaDB.php not found"
fi
echo "---- show SQL.php 1520-1620 (abstract getUpsertStatement) ----"
if [ -f src/Database/Adapter/SQL.php ]; then
sed -n '1520,1620p' src/Database/Adapter/SQL.php || true
else
echo "src/Database/Adapter/SQL.php not found"
fi
echo "---- show SQL.php 1980-2260 (createOrUpdateDocuments area) ----"
if [ -f src/Database/Adapter/SQL.php ]; then
sed -n '1980,2260p' src/Database/Adapter/SQL.php || true
else
echo "src/Database/Adapter/SQL.php not found"
fi
echo "---- search for getUpsertStatement call sites ----"
rg -n --hidden --no-ignore -S "getUpsertStatement\(" || true
echo "---- search for ON DUPLICATE KEY UPDATE in MariaDB.php ----"
rg -n --hidden --no-ignore -S "ON DUPLICATE KEY UPDATE|ON DUPLICATE KEY" src/Database/Adapter/MariaDB.php || true
echo "---- search for _updatedBy occurrences in MariaDB.php ----"
rg -n --hidden --no-ignore -S "_updatedBy" src/Database/Adapter/MariaDB.php || trueLength of output: 20899 Upsert increment path must update _updatedBy (MariaDB adapter) createOrUpdateDocuments sets _updatedBy (src/Database/Adapter/SQL.php:2183-2185), but MariaDB::getUpsertStatement’s increment branch only updates the incremented attribute and _updatedAt — add _updatedBy to the increment ON DUPLICATE KEY UPDATE clause (e.g. include $getUpdateClause('_updatedBy') so the sharedTables IF logic is preserved). 🤖 Prompt for AI Agents |
||
|
|
||
| if (!empty($document->getSequence())) { | ||
|
|
@@ -2504,6 +2530,14 @@ public function find(Document $collection, array $queries = [], ?int $limit = 25 | |
| $results[$index]['$updatedAt'] = $document['_updatedAt']; | ||
| unset($results[$index]['_updatedAt']); | ||
| } | ||
| if (\array_key_exists('_createdBy', $document)) { | ||
| $results[$index]['$createdBy'] = $document['_createdBy']; | ||
| unset($results[$index]['_createdBy']); | ||
| } | ||
| if (\array_key_exists('_updatedBy', $document)) { | ||
| $results[$index]['$updatedBy'] = $document['_updatedBy']; | ||
| unset($results[$index]['_updatedBy']); | ||
| } | ||
| if (\array_key_exists('_permissions', $document)) { | ||
| $results[$index]['$permissions'] = \json_decode($document['_permissions'] ?? '[]', true); | ||
| unset($results[$index]['_permissions']); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this added for any SQL adapters 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its present -> https://github.com/utopia-php/database/pull/680/files#diff-14149d1580fa54670629e57c6d684530e50ab17fb75d888418906c30b1595225R1261