Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 58
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
f77eb9a484d0451bf9fb828a979e8a85666a6789e32a4805e67791d16e40e795e179691140b58c20f225e7063902cd4666731fea0f4a449be95802fbd8a8acFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -237,6 +237,8 @@ public function createCollection(string $name, array $attributes = [], array $in | ||
| " . $sqlTenant . " | ||
| \"_createdAt\" TIMESTAMP(3) DEFAULT NULL, | ||
| \"_updatedAt\" TIMESTAMP(3) DEFAULT NULL, | ||
| \"_createdBy\" VARCHAR(255) DEFAULT NULL, | ||
| \"_updatedBy\" VARCHAR(255) DEFAULT NULL, | ||
| " . \implode(' ', $attributeStrings) . " | ||
| _permissions TEXT DEFAULT NULL | ||
| ); | ||
| @@ -247,13 +249,17 @@ public function createCollection(string $name, array $attributes = [], array $in | ||
| CREATE UNIQUE INDEX \"{$namespace}_{$this->tenant}_{$id}_uid\" ON {$this->getSQLTable($id)} (\"_uid\", \"_tenant\"); | ||
| CREATE INDEX \"{$namespace}_{$this->tenant}_{$id}_created\" ON {$this->getSQLTable($id)} (_tenant, \"_createdAt\"); | ||
| CREATE INDEX \"{$namespace}_{$this->tenant}_{$id}_updated\" ON {$this->getSQLTable($id)} (_tenant, \"_updatedAt\"); | ||
| CREATE INDEX \"{$namespace}_{$this->tenant}_{$id}_created_by\" ON {$this->getSQLTable($id)} (_tenant, \"_createdBy\"); | ||
| CREATE INDEX \"{$namespace}_{$this->tenant}_{$id}_updated_by\" ON {$this->getSQLTable($id)} (_tenant, \"_updatedBy\"); | ||
| CREATE INDEX \"{$namespace}_{$this->tenant}_{$id}_tenant_id\" ON {$this->getSQLTable($id)} (_tenant, _id); | ||
| "; | ||
| } else { | ||
| $collection .= " | ||
| CREATE UNIQUE INDEX \"{$namespace}_{$id}_uid\" ON {$this->getSQLTable($id)} (\"_uid\"); | ||
| CREATE INDEX \"{$namespace}_{$id}_created\" ON {$this->getSQLTable($id)} (\"_createdAt\"); | ||
| CREATE INDEX \"{$namespace}_{$id}_updated\" ON {$this->getSQLTable($id)} (\"_updatedAt\"); | ||
| CREATE INDEX \"{$namespace}_{$id}_created_by\" ON {$this->getSQLTable($id)} (\"_createdBy\"); | ||
| CREATE INDEX \"{$namespace}_{$id}_updated_by\" ON {$this->getSQLTable($id)} (\"_updatedBy\"); | ||
| "; | ||
| } | ||
| @@ -961,6 +967,8 @@ public function createDocument(Document $collection, Document $document): Docume | ||
| $attributes = $document->getAttributes(); | ||
| $attributes['_createdAt'] = $document->getCreatedAt(); | ||
| $attributes['_updatedAt'] = $document->getUpdatedAt(); | ||
| $attributes['_createdBy'] = $document->getCreatedBy(); | ||
| $attributes['_updatedBy'] = $document->getUpdatedBy(); | ||
| $attributes['_permissions'] = \json_encode($document->getPermissions()); | ||
| if ($this->sharedTables) { | ||
| @@ -1075,6 +1083,8 @@ public function updateDocument(Document $collection, string $id, Document $docum | ||
| $attributes = $document->getAttributes(); | ||
| $attributes['_createdAt'] = $document->getCreatedAt(); | ||
| $attributes['_updatedAt'] = $document->getUpdatedAt(); | ||
| $attributes['_createdBy'] = $document->getCreatedBy(); | ||
| $attributes['_updatedBy'] = $document->getUpdatedBy(); | ||
| $attributes['_permissions'] = json_encode($document->getPermissions()); | ||
ArnabChatterjee20k marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| $name = $this->filter($collection); | ||
| @@ -1343,12 +1353,13 @@ protected function getUpsertStatement( | ||
| * @param string $attribute | ||
| * @param int|float $value | ||
| * @param string $updatedAt | ||
| * @param string|null $updatedBy | ||
| * @param int|float|null $min | ||
| * @param int|float|null $max | ||
| * @return bool | ||
| * @throws DatabaseException | ||
| */ | ||
| public function increaseDocumentAttribute(string $collection, string $id, string $attribute, int|float $value, string $updatedAt, int|float|null $min = null, int|float|null $max = null): bool | ||
| public function increaseDocumentAttribute(string $collection, string $id, string $attribute, int|float $value, string $updatedAt, ?string $updatedBy, int|float|null $min = null, int|float|null $max = null): bool | ||
| { | ||
| $name = $this->filter($collection); | ||
| $attribute = $this->filter($attribute); | ||
| @@ -1360,7 +1371,8 @@ public function increaseDocumentAttribute(string $collection, string $id, string | ||
| UPDATE {$this->getSQLTable($name)} | ||
| SET | ||
| \"{$attribute}\" = \"{$attribute}\" + :val, | ||
| \"_updatedAt\" = :updatedAt | ||
| \"_updatedAt\" = :updatedAt, | ||
| \"_updatedBy\" = :updatedBy | ||
| WHERE _uid = :_uid | ||
| {$this->getTenantQuery($collection)} | ||
| "; | ||
| @@ -1373,6 +1385,7 @@ public function increaseDocumentAttribute(string $collection, string $id, string | ||
| $stmt->bindValue(':_uid', $id); | ||
| $stmt->bindValue(':val', $value); | ||
| $stmt->bindValue(':updatedAt', $updatedAt); | ||
| $stmt->bindValue(':updatedBy', $updatedBy); | ||
| if ($this->sharedTables) { | ||
| $stmt->bindValue(':_tenant', $this->tenant); | ||
| 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.
Uh oh!There was an error while loading. Please reload this page. | ||
| 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/bashset -euo pipefail
echo"PWD: $(pwd)"echo"---- locate SQL.php ----"
rg -n --hidden --no-ignore -S "src/Database/Adapter/SQL.php"||trueecho"---- show SQL.php 2130-2200 ----"if [ -f src/Database/Adapter/SQL.php ];then
sed -n '2130,2200p' src/Database/Adapter/SQL.php ||trueelseecho"src/Database/Adapter/SQL.php not found"fiecho"---- search for getUpsertStatement definitions ----"
rg -n --hidden --no-ignore -S "function\s+getUpsertStatement"||trueecho"---- search for class MariaDB ----"
rg -n --hidden --no-ignore -S "class\s+MariaDB"||trueecho"---- show any MariaDB file contents around getUpsertStatement if found ----"forfin$(rg -n --hidden --no-ignore -S "class\s+MariaDB" -g '!vendor' --files-with-matches || true);doecho"---- $f ----"
sed -n '1,240p'"$f"||truedoneecho"---- search for _updatedBy/_createdBy usages ----"
rg -n --hidden --no-ignore -S "_updatedBy|_createdBy"||trueecho"---- 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/bashset -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 ||trueelseecho"src/Database/Adapter/MariaDB.php not found"fiecho"---- show SQL.php 1520-1620 (abstract getUpsertStatement) ----"if [ -f src/Database/Adapter/SQL.php ];then
sed -n '1520,1620p' src/Database/Adapter/SQL.php ||trueelseecho"src/Database/Adapter/SQL.php not found"fiecho"---- show SQL.php 1980-2260 (createOrUpdateDocuments area) ----"if [ -f src/Database/Adapter/SQL.php ];then
sed -n '1980,2260p' src/Database/Adapter/SQL.php ||trueelseecho"src/Database/Adapter/SQL.php not found"fiecho"---- search for getUpsertStatement call sites ----"
rg -n --hidden --no-ignore -S "getUpsertStatement\("||trueecho"---- 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 ||trueecho"---- 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']); | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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