Internal attributes defaults
Summary by CodeRabbit
-
Bug Fixes
- Internal metadata fields are now consistently included in query results with a new prefixed naming convention.
- Permission checks and timestamp formatting on documents have been refined for accuracy.
- Internal attributes are now properly filtered during document encoding to prevent exposure.
-
Tests
- Updated tests to expect internal attributes with the new prefixed keys.
- Adjusted test assertions to match the revised document structure and selection logic.
Walkthrough
These changes refactor how internal metadata attributes are handled and exposed in the database layer. Internal attributes are now consistently prefixed with main::$ in query results and document objects. Permission checks, attribute filtering, and test assertions are updated to use this new convention. Additional debug output and utility methods for internal attribute detection are introduced.
Changes
| Files/Areas | Change Summary |
|---|---|
| src/Database/Adapter/SQL.php | Added addHiddenAttribute method for internal metadata projection; updated getAttributeProjection to always append hidden attributes with main::$ prefix; removed old explicit internal key additions; decoded JSON permissions and cast tenant in getDocument. |
| src/Database/Database.php | Added static isInternalAttribute method; updated permission checks to use main::$permissions; set and formatted internal attributes with main::$ prefix in documents; cleaned internal attributes during encoding; commented out automatic internal attribute inclusion in selections; added debug output and "todo" comments regarding permission keys in relations. |
| src/Database/Document.php | Modified permission-related methods to accept optional attribute key parameter (default '$permissions'); replaced internal attribute filtering with call to Database::isInternalAttribute. |
| tests/e2e/Adapter/Scopes/DocumentTests.php | Updated assertions to expect internal/system attributes with main::$ prefix instead of direct keys; added blank line after assertion in one test. |
| tests/e2e/Adapter/Scopes/RelationshipTests.php | Updated assertions in selection tests to expect internal attributes with main::$ prefix; adjusted query selections; minor whitespace and commented-out lines added. |
Sequence Diagram(s)
sequenceDiagram
participant Client
participant Database
participant SQLAdapter
Client->>Database: getDocument(id, selections)
Database->>SQLAdapter: getDocument(id, selections)
SQLAdapter->>SQLAdapter: getAttributeProjection(selections, prefix)
SQLAdapter->>SQLAdapter: addHiddenAttribute(selections)
SQLAdapter->>SQLAdapter: Build SELECT with user and hidden attributes
SQLAdapter->>Database: Return document with main::$ attributes
Database->>Database: Format timestamps, set main::$collection, etc.
Database->>Client: Return document with main::$ attributes
Possibly related PRs
- utopia-php/database#606: Also modifies
getAttributeProjectioninsrc/Database/Adapter/SQL.php, changing its signature and how projections are constructed, indicating a direct connection.
Poem
A hop, a skip, a hidden key,
Now "main::$" is what you'll see.
Permissions checked, projections neat,
With debug logs, the code's complete.
Tests now match the rabbit's plan,
Internal fields—catch them if you can! 🐇
📜 Recent review details
Configuration used: .coderabbit.yaml Review profile: CHILL Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between b23b8a8a918819df634a5054a0ca5726e916dc90 and 42600a64b2c368cc8bc0aaf031aa9af50d308776.
📒 Files selected for processing (4)
-
src/Database/Adapter/SQL.php(3 hunks) -
src/Database/Database.php(16 hunks) -
src/Database/Document.php(3 hunks) -
tests/e2e/Adapter/Scopes/DocumentTests.php(9 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
- src/Database/Document.php
- src/Database/Adapter/SQL.php
- tests/e2e/Adapter/Scopes/DocumentTests.php
- src/Database/Database.php
⏰ Context from checks skipped due to timeout of 90000ms (11)
- GitHub Check: Adapter Tests (SharedTables/SQLite)
- GitHub Check: Adapter Tests (SharedTables/Postgres)
- GitHub Check: Adapter Tests (SharedTables/MySQL)
- GitHub Check: Adapter Tests (SharedTables/MariaDB)
- GitHub Check: Adapter Tests (Pool)
- GitHub Check: Adapter Tests (Postgres)
- GitHub Check: Adapter Tests (SQLite)
- GitHub Check: Adapter Tests (Mirror)
- GitHub Check: Adapter Tests (MySQL)
- GitHub Check: Adapter Tests (MariaDB)
- GitHub Check: Unit Test
✨ Finishing Touches
- [ ] 📝 Generate Docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
-
I pushed a fix in commit <commit_id>, please review it. -
Explain this complex logic. -
Open a follow-up GitHub issue for this discussion.
-
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:-
@coderabbitai explain this code block. -
@coderabbitai modularize this function.
-
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:-
@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase. -
@coderabbitai read src/utils.ts and explain its main purpose. -
@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format. -
@coderabbitai help me debug CodeRabbit configuration file.
-
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
-
@coderabbitai pauseto pause the reviews on a PR. -
@coderabbitai resumeto resume the paused reviews. -
@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository. -
@coderabbitai full reviewto do a full review from scratch and review all the files again. -
@coderabbitai summaryto regenerate the summary of the PR. -
@coderabbitai generate docstringsto generate docstrings for this PR. -
@coderabbitai generate sequence diagramto generate a sequence diagram of the changes in this PR. -
@coderabbitai resolveresolve all the CodeRabbit review comments. -
@coderabbitai configurationto show the current CodeRabbit configuration for the repository. -
@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.