Skip to content

Conversation

@fogelito
Copy link
Contributor

@fogelito fogelito commented Jul 17, 2025

Summary by CodeRabbit

  • New Features

    • Added checks to ensure array attribute indexing is only allowed if supported by the database adapter.
    • Introduced new methods to indicate support for array index features in database adapters.
  • Bug Fixes

    • Improved error handling by throwing exceptions when attempting to index array attributes on unsupported adapters.
  • Tests

    • Updated tests to conditionally run array index-related checks based on adapter capabilities, ensuring accurate and relevant test coverage.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 17, 2025

Walkthrough

Support for indexing array attributes was formalized across the database adapter interface and implementations. New abstract methods were introduced to declare support for array and cast index arrays. Control flow in the database and test code was updated to check these capabilities before performing related operations, ensuring compatibility across different adapters.

Changes

File(s) Change Summary
src/Database/Adapter.php Added abstract methods getSupportForIndexArray() and getSupportForCastIndexArray(); reorganized their placement.
src/Database/Adapter/MySQL.php Added getSupportForIndexArray() returning false; updated getSupportForCastIndexArray() to depend on it.
src/Database/Adapter/SQL.php Added getSupportForIndexArray() returning true.
src/Database/Adapter/Pool.php Added getSupportForIndexArray() and moved getSupportForCastIndexArray() to earlier position; both delegate to adapter.
src/Database/Database.php Added checks for adapter support before indexing array attributes; throws exception if unsupported.
tests/e2e/Adapter/Scopes/AttributeTests.php Made array index tests conditional on adapter support; restructured test logic accordingly.
tests/e2e/Adapter/Scopes/CollectionTests.php Conditionally included "cards" index and related assertions based on adapter support; added PHPDoc hints.
tests/e2e/Adapter/Scopes/IndexTests.php Conditionally created array attribute index in test based on adapter support.

Sequence Diagram(s)

sequenceDiagram
    participant TestSuite
    participant Database
    participant Adapter

    TestSuite->>Database: createCollection / createIndex (with array attribute)
    Database->>Adapter: getSupportForIndexArray()
    Adapter-->>Database: true/false
    alt Adapter supports array index
        Database->>Database: Proceed with index creation
    else Adapter does not support array index
        Database->>Database: Throw IndexException
    end
Loading

Poem

🐇
A hop and a skip, array indexes appear,
But only where adapters say, "Yes, they're here!"
MySQL says "Nope!" with a bug in its way,
SQL says "Sure!"—let's index array!
Now tests check support before they run,
Ensuring smooth hopping for everyone.


📜 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 75ee16d and e797c01.

📒 Files selected for processing (1)
  • src/Database/Adapter/Pool.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 (1)
src/Database/Adapter/Pool.php (4)
src/Database/Adapter/MySQL.php (2)
  • getSupportForIndexArray (81-88)
  • getSupportForCastIndexArray (90-97)
src/Database/Adapter.php (2)
  • getSupportForIndexArray (900-900)
  • getSupportForCastIndexArray (907-907)
src/Database/Adapter/SQL.php (2)
  • getSupportForIndexArray (1377-1380)
  • getSupportForCastIndexArray (1382-1385)
src/Database/Mirror.php (1)
  • delegate (88-103)
🔇 Additional comments (1)
src/Database/Adapter/Pool.php (1)

338-346: LGTM! Clean implementation following established patterns.

Both methods correctly implement the delegation pattern consistent with other getSupportFor*() methods in the class. The placement is logical and the implementation properly forwards calls to the underlying adapter instances.

✨ 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.

@fogelito fogelito requested a review from abnegate July 17, 2025 12:23
Copy link
Member

@abnegate abnegate left a comment

Choose a reason for hiding this comment

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

Looks good, let's add a patch script to drop all existing array-attribute indexes too

@abnegate abnegate merged commit 83278d6 into main Jul 18, 2025
15 checks passed
@abnegate abnegate deleted the disable-array-index-mysql branch July 18, 2025 00:05
abnegate added a commit that referenced this pull request Aug 5, 2025
…ysql"

This reverts commit 83278d6, reversing
changes made to eb2f759.
abnegate added a commit that referenced this pull request Aug 11, 2025
…ysql"

This reverts commit 83278d6, reversing
changes made to eb2f759.
abnegate added a commit that referenced this pull request Aug 11, 2025
Revert "Merge pull request #627 from utopia-php/disable-array-index-m…
abnegate added a commit that referenced this pull request Aug 14, 2025
@coderabbitai coderabbitai bot mentioned this pull request Aug 14, 2025
@coderabbitai coderabbitai bot mentioned this pull request Oct 7, 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