Skip to content

Conversation

@fogelito
Copy link
Contributor

@fogelito fogelito commented Jul 9, 2025

Summary by CodeRabbit

  • New Features

    • Improved handling of sequence data for documents during batch creation and update operations. Returned documents now include updated sequence information.
  • Bug Fixes

    • Ensured that documents returned from batch operations always include the correct sequence data.
  • Tests

    • Added assertions to verify the presence and update of sequence information in documents during upsert operations.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 9, 2025

Walkthrough

An abstract getSequences method was added to the Adapter hierarchy, with concrete implementations and delegation in relevant subclasses. Sequence fetching was refactored to operate directly on document arrays. Calls to update sequences after batch create or update operations were introduced in the database layer. Test logic was updated to assert sequence presence before and after document updates.

Changes

File(s) Change Summary
src/Database/Adapter.php Added abstract method getSequences(string $collection, array $documents): array to Adapter class.
src/Database/Adapter/Pool.php Added public getSequences method delegating call to underlying adapter.
src/Database/Adapter/SQL.php Changed getSequences to public, accept documents, update sequences on documents, removed old sequence fetching in createDocuments.
src/Database/Adapter/MariaDB.php Removed collection of document IDs/tenants and sequence fetching logic from createOrUpdateDocuments.
src/Database/Database.php Added calls to getSequences after batch create and create-or-update operations to update document sequences.
tests/e2e/Adapter/Scopes/DocumentTests.php Added assertions checking $sequence property presence before and after document upserts.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Database
    participant Adapter
    participant SQL

    Client->>Database: createDocuments(collection, documents)
    Database->>Adapter: createDocuments(collection, documents)
    Adapter->>SQL: createDocuments(collection, documents)
    SQL-->>Adapter: [inserted documents]
    Adapter-->>Database: [inserted documents]
    Database->>Adapter: getSequences(collection, documents)
    Adapter->>SQL: getSequences(collection, documents)
    SQL-->>Adapter: [documents with sequences]
    Adapter-->>Database: [documents with sequences]
    Database-->>Client: [documents with sequences]
Loading

Poem

In the warren of code, a new path appears,
Sequences fetched with fewer fears.
Documents now know their place,
With updated flows, they run the race.
Debugs and asserts, the tests now cheer—
The rabbit hops on, the way is clear!
🐇✨


📜 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 df87764 and bf7404b.

📒 Files selected for processing (4)
  • src/Database/Adapter.php (1 hunks)
  • src/Database/Adapter/Pool.php (1 hunks)
  • src/Database/Adapter/SQL.php (1 hunks)
  • src/Database/Database.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/Database/Adapter.php
  • src/Database/Adapter/Pool.php
  • src/Database/Database.php
  • src/Database/Adapter/SQL.php
✨ 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.

❤️ Share
🪧 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 @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in 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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere 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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eb2f759 and 703b387.

📒 Files selected for processing (6)
  • src/Database/Adapter.php (1 hunks)
  • src/Database/Adapter/MariaDB.php (1 hunks)
  • src/Database/Adapter/Pool.php (1 hunks)
  • src/Database/Adapter/SQL.php (1 hunks)
  • src/Database/Database.php (2 hunks)
  • tests/e2e/Adapter/Scopes/DocumentTests.php (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: ArnabChatterjee20k
PR: utopia-php/database#613
File: src/Database/Adapter/Postgres.php:1254-1319
Timestamp: 2025-07-01T11:31:37.438Z
Learning: In PostgreSQL adapter methods like getUpsertStatement, complexity for database-specific SQL generation is acceptable when the main business logic is properly separated in the parent SQL adapter class, following the adapter pattern where each database adapter handles its own SQL syntax requirements.
🧬 Code Graph Analysis (2)
src/Database/Adapter.php (2)
src/Database/Adapter/Pool.php (1)
  • getSequences (493-496)
src/Database/Adapter/SQL.php (1)
  • getSequences (720-771)
src/Database/Adapter/Pool.php (3)
src/Database/Adapter.php (1)
  • getSequences (736-736)
src/Database/Adapter/SQL.php (1)
  • getSequences (720-771)
src/Database/Mirror.php (1)
  • delegate (88-103)
🪛 GitHub Actions: CodeQL
src/Database/Adapter.php

[error] 736-736: PHPStan: Method Utopia\Database\Adapter::getSequences() has parameter $documents with no value type specified in iterable type array.


[error] 736-736: PHPStan: Method Utopia\Database\Adapter::getSequences() return type has no value type specified in iterable type array.

src/Database/Adapter/Pool.php

[error] 493-493: PHPStan: Method Utopia\Database\Adapter\Pool::getSequences() has parameter $documents with no value type specified in iterable type array.


[error] 493-493: PHPStan: Method Utopia\Database\Adapter\Pool::getSequences() return type has no value type specified in iterable type array.

src/Database/Adapter/SQL.php

[error] 770-770: PHPStan: Method Utopia\Database\Adapter\SQL::getSequences() should return array but returns array<Utopia\Database\Document>.

🪛 GitHub Actions: Linter
tests/e2e/Adapter/Scopes/DocumentTests.php

[error] 1-1: PSR 12 linting failed: statement_indentation style issue detected.

src/Database/Adapter/SQL.php

[error] 1-1: PSR 12 linting failed: statement_indentation style issue detected.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Setup & Build Docker Image
🔇 Additional comments (5)
tests/e2e/Adapter/Scopes/DocumentTests.php (1)

449-449: Good validation of sequence data.

This assertion correctly verifies that documents returned from upsert operations contain the expected $sequence key, which aligns with the refactored sequence handling mentioned in the summary.

src/Database/Adapter/MariaDB.php (1)

1188-1188: Sequence Handling Verified

I’ve confirmed that:

  • getSequences is declared in src/Database/Adapter.php and implemented in src/Database/Adapter/SQL.php (with Pool adapter delegating to it).
  • src/Database/Database.php invokes $this->adapter->getSequences(...) immediately after each batch of create/update calls.
  • All sequence-fetching logic has been successfully moved out of the MariaDB adapter and centralized at the Database class level.

This refactoring cleanly separates database-specific operations from business logic. LGTM! 🚀

src/Database/Database.php (2)

3754-3754: LGTM! Proper sequence update placement.

The addition of getSequences call is well-positioned after the batch creation and before relationship resolution and decoding. This ensures documents have updated sequence data before further processing.


5071-5071: LGTM! Consistent sequence handling.

Good consistency with the createDocuments method - both batch operations now properly update sequence data using the same pattern and placement.

src/Database/Adapter/SQL.php (1)

736-736: Fix tenant binding key concatenation.

The tenant binding key uses incorrect string concatenation syntax. It should use curly braces for proper interpolation.

Apply this diff to fix the tenant binding key:

-                    $binds[':_tenant_'.$i] = $document->getTenant();
+                    $binds[":_tenant_{$i}"] = $document->getTenant();

Likely an incorrect or invalid review comment.

@abnegate abnegate merged commit bfc66eb into main Jul 21, 2025
15 checks passed
@abnegate abnegate deleted the bulk-sequences branch July 21, 2025 01:17
This was referenced Jul 29, 2025
@coderabbitai coderabbitai bot mentioned this pull request Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants