Skip to content

feat(adapter): add support for upsert on unique index across database…#871

Merged
abnegate merged 1 commit intomainfrom
index-support-method
Apr 30, 2026
Merged

feat(adapter): add support for upsert on unique index across database…#871
abnegate merged 1 commit intomainfrom
index-support-method

Conversation

@ArnabChatterjee20k
Copy link
Copy Markdown
Contributor

@ArnabChatterjee20k ArnabChatterjee20k commented Apr 30, 2026

… adapters

Summary by CodeRabbit

Release Notes

  • New Features
    • Added capability detection for upsert operations on unique indexes across all database adapters, allowing the system to determine which backends support this functionality.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2409047f-4d99-46e7-833a-64a2584253ee

📥 Commits

Reviewing files that changed from the base of the PR and between 688d942 and 66ec17e.

📒 Files selected for processing (7)
  • src/Database/Adapter.php
  • src/Database/Adapter/MariaDB.php
  • src/Database/Adapter/Memory.php
  • src/Database/Adapter/Mongo.php
  • src/Database/Adapter/Pool.php
  • src/Database/Adapter/Postgres.php
  • src/Database/Adapter/SQLite.php

📝 Walkthrough

Walkthrough

This pull request adds a new capability-checking abstract method getSupportForUpsertOnUniqueIndex() to the base Adapter class and implements it across all six database adapters. MariaDB reports support for this capability (true), while Memory, Mongo, Postgres, and SQLite report no support (false). The Pool adapter delegates to its underlying adapter.

Changes

Cohort / File(s) Summary
Base Adapter Declaration
src/Database/Adapter.php
Introduces abstract method getSupportForUpsertOnUniqueIndex(): bool to define a new capability contract for all adapters.
Adapter Implementations
src/Database/Adapter/MariaDB.php, src/Database/Adapter/Memory.php, src/Database/Adapter/Mongo.php, src/Database/Adapter/Pool.php, src/Database/Adapter/Postgres.php, src/Database/Adapter/SQLite.php
Implements getSupportForUpsertOnUniqueIndex() method across all adapters. MariaDB returns true; Memory, Mongo, Postgres, and SQLite return false. Pool delegates to the underlying adapter.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • fogelito
  • abnegate

Poem

🐰 A new method hops into the database warren,
Six adapters pledge their upsert devotion,
MariaDB stands tall with truth,
While others wisely confess—nay, forsooth!
Each adapter knows its own magic best.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a new capability method for upsert on unique index support across all database adapters.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch index-support-method

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PHPStan (2.1.51)

PHPStan was skipped because the sandbox runner could not parse its output.


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
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 30, 2026

Greptile Summary

This PR adds getSupportForUpsertOnUniqueIndex() as a new abstract capability flag across all six database adapters, returning true only for MariaDB (which fires ON DUPLICATE KEY UPDATE on any unique key conflict). The flag stubs are correct at the individual adapter level, but the method is never called anywhere in the codebase — no gate in Database.php, no task script, and no tests — so the declared capability has no runtime effect and the feature is effectively incomplete.

Confidence Score: 3/5

Safe to merge without breakage, but the feature is a no-op — the capability flag is never consumed.

One P1 finding: the new abstract method is defined and implemented in all adapters but never read by any higher-level code, meaning the entire feature stub is dead code. No existing behaviour is broken, but the PR title claims working support for upsert on unique index which is not yet true.

src/Database/Adapter.php — the abstract declaration needs a corresponding call-site in Database.php or a task/test that gates on the new flag.

Important Files Changed

Filename Overview
src/Database/Adapter.php Adds abstract getSupportForUpsertOnUniqueIndex() — method is never called anywhere in the codebase, making the feature stub incomplete.
src/Database/Adapter/MariaDB.php Implements the flag as true; consistent with ON DUPLICATE KEY UPDATE firing on any unique key.
src/Database/Adapter/Postgres.php Returns false — technically correct for the current hardcoded-_uid implementation, but no comment clarifies this is "not yet implemented" rather than "unsupported by the engine".
src/Database/Adapter/SQLite.php Returns false, consistent with getSupportForUpserts() being false for SQLite.
src/Database/Adapter/Mongo.php Returns false; straightforward stub addition.
src/Database/Adapter/Memory.php Returns false; consistent with Memory not implementing upserts at all.
src/Database/Adapter/Pool.php Delegates to the underlying adapter via the standard delegate() pattern; correct.

Reviews (1): Last reviewed commit: "feat(adapter): add support for upsert on..." | Re-trigger Greptile

Comment thread src/Database/Adapter.php
Comment thread src/Database/Adapter/Postgres.php
@abnegate abnegate merged commit e5c9edd into main Apr 30, 2026
45 checks passed
@abnegate abnegate deleted the index-support-method branch April 30, 2026 09:39
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.

2 participants