Skip to content

Feat txn #10023

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

Draft
wants to merge 68 commits into
base: 1.8.x
Choose a base branch
from
Draft

Feat txn #10023

wants to merge 68 commits into from

Conversation

abnegate
Copy link
Member

What does this PR do?

(Provide a description of what this PR does and why it's needed.)

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Screenshots may also be helpful.)

Related PRs and Issues

  • (Related PR or issue)

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

Copy link
Contributor

coderabbitai bot commented Jun 18, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

Adds transactional support for databases and grids: two new metadata collections (transactions, transactionLogs), transaction TTL constants, new transaction-related error codes and Exception constants, two new scopes (transactions.read, transactions.write), and validators/models (Operation, Transactions query validator, Transaction model/list). Marks SDK Response readonly and registers transaction models. Extends many document and grid endpoints to accept an optional transactionId for staging operations, and adds HTTP endpoints to create, list, get, update, delete transactions and to add operations.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

Suggested reviewers

  • ItzNotABug
  • Meldiron
  • TorstenDittmann
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-txn

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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

github-actions bot commented Jun 18, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
golang.org/x/crypto v0.31.0 CVE-2025-22869 HIGH
golang.org/x/oauth2 v0.24.0 CVE-2025-22868 HIGH
stdlib 1.22.10 CVE-2025-47907 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

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: 13

♻️ Duplicate comments (4)
app/controllers/api/databases.php (4)

4598-4623: Same counter / limit hole for updateDocument staging

updateDocument writes a log entry (action =update) but likewise forgets to bump transactions.operations, leaving the transaction inconsistent and limits unenforced.


5256-5263: Bulk-update staging also forgets to bump operations

The bulkUpdate path logs the action but never adjusts transactions.operations, compounding the inconsistency noted above.


5355-5376: Bulk-upsert staging: same missing counter update

Identical issue – please ensure the transaction document is patched alongside the logs.


5482-5488: Delete-within-transaction not counted

The deleteDocument staging block writes the log but omits the counter update.

🧹 Nitpick comments (7)
app/init/constants.php (1)

55-57: Constants fine, but add unit in the name or php-doc for clarity

All three TTL constants are seconds, while many other timeout constants are suffixed with _MILLISECONDS.
Consider either renaming (…_SECONDS) or adding a short php-doc to avoid confusion when the values are consumed next to the millisecond ones.

src/Appwrite/Utopia/Database/Validator/Operation.php (2)

57-64: Type validation runs before presence validation for data.

Because data isn’t guaranteed to exist (see above), the is_array($value['data']) call will still emit a notice even if you add it to $required but leave this block here.
Move the data-presence check to the loop above or guard with array_key_exists.


65-69: Inefficient in_array call in a hot path.

$this->actions is static – convert it to a const array + use isset($map[$action]) for O(1) lookup if performance on large payloads matters.

src/Appwrite/Utopia/Response/Model/Transaction.php (2)

31-36: status field lacks server-side enforcement of allowed values.

Add the allowed key to the rule so malformed responses can be caught early.

-            ->addRule('status', [
-                'type' => self::TYPE_STRING,
-                'description' => 'Current status of the transaction. One of: pending, committing, committed, rolled_back, failed.',
-                'default' => 'pending',
-                'example' => 'pending',
-            ])
+            ->addRule('status', [
+                'type'     => self::TYPE_STRING,
+                'allowed'  => ['pending', 'committing', 'committed', 'rolled_back', 'failed'],
+                'description' => 'Current status of the transaction.',
+                'default' => 'pending',
+                'example' => 'pending',
+            ])

12-18: Model is missing the operations counter present in the collection.

Exposing it would let clients display progress and enforce limits without extra calls.

app/config/collections/projects.php (1)

2515-2567: Consider adding an automatic TTL index on expiresAt.

A regular KEY index won’t clean up rows automatically.
If you rely on MySQL you’ll need a scheduled job; in Mongo-like stores you can switch to a TTL index to avoid manual sweeps.

tests/e2e/Services/Databases/DatabasesBase.php (1)

4110-4110: Fix grammatical issue in comment

-                '$updatedAt' => '2022-08-01 13:09:23.050' // system will update it not api
+                '$updatedAt' => '2022-08-01 13:09:23.050' // system will update it, not API
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d841511 and 910f270.

📒 Files selected for processing (13)
  • app/config/collections/projects.php (1 hunks)
  • app/config/errors.php (1 hunks)
  • app/config/roles.php (1 hunks)
  • app/config/scopes.php (1 hunks)
  • app/controllers/api/databases.php (31 hunks)
  • app/init/constants.php (1 hunks)
  • src/Appwrite/Extend/Exception.php (1 hunks)
  • src/Appwrite/SDK/Response.php (1 hunks)
  • src/Appwrite/Utopia/Database/Validator/Operation.php (1 hunks)
  • src/Appwrite/Utopia/Database/Validator/Queries/Transactions.php (1 hunks)
  • src/Appwrite/Utopia/Response.php (4 hunks)
  • src/Appwrite/Utopia/Response/Model/Transaction.php (1 hunks)
  • tests/e2e/Services/Databases/DatabasesBase.php (7 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (16)
src/Appwrite/SDK/Response.php (1)

5-5: readonly requires PHP 8.2 – confirm your minimum runtime

Declaring the whole class as readonly is great for immutability, but this syntax is supported only from PHP 8.2 upward.
If the project still targets 8.1 or earlier it will fatal-error at load‐time.
Please double-check the composer.json / CI matrix and bump the platform requirement if necessary.

app/config/scopes.php (1)

43-48: Scope names added correctly – remember to wire them into roles & docs

No functional issues spotted with the new transactions.* scopes.
Just ensure they are:

  1. Added to the relevant roles in app/config/roles.php.
  2. Reflected in the public API docs / SDK generation matrix.
app/config/errors.php (1)

813-848: Comprehensive error set – keep codes unique

The new transaction error definitions look consistent and follow existing naming & HTTP-code conventions. ✔️
Double-check that no other constant shares the numeric 410/409/400 slots for the same domain to avoid ambiguity in clients.

src/Appwrite/Utopia/Database/Validator/Operation.php (1)

80-83: getType() advertises an object while isArray() returns true.

Down-stream consumers might treat TYPE_OBJECT as a map of named properties, not a numerically-indexed array. Verify this aligns with Utopia’s expectations, otherwise return TYPE_ARRAY.

src/Appwrite/Extend/Exception.php (1)

232-240: Constants addition LGTM.

Names follow existing style and are unique; no further issues spotted.

app/config/collections/projects.php (1)

2570-2649: Schema and validator drift (action enum).

transactionLogs.action comment lists increment | decrement, but these are not accepted by Operation validator (see earlier comment).
Align both sides to prevent runtime rejects.

src/Appwrite/Utopia/Response.php (5)

108-108: Transaction model import added – looks good

The new Transaction model is correctly imported and used later in the constructor.


169-170: Constants registered for transactions

MODEL_TRANSACTION and MODEL_TRANSACTION_LIST are consistent with the existing naming scheme and ensure the new entities can be referenced everywhere.


420-420: List registration for transactions

BaseList('Transaction List', … 'transactions', …) wires the collection path and the item model properly. No issues spotted.


519-519: Entity model registration

->setModel(new Transaction()) finalises the response-layer support. All good.


375-375: Let’s inspect the surrounding routes to confirm the intended URL segment for Auth Providers:

#!/bin/bash
sed -n '350,430p' src/Appwrite/Utopia/Response.php
app/config/roles.php (2)

7-9: Verify that newly added scopes are defined

Scopes such as assistant.read, avatars.read, graphql, home, and rules.read have been added for member roles. Make sure they are present in app/config/scopes.php; otherwise authentication will reject these tokens.

Also applies to: 12-19, 22-30


80-82: Transactions scopes – double-check consistency

transactions.read / transactions.write are now assigned to admins. Confirm that:

  1. They are defined in scopes.php.
  2. All new API routes are protected by the corresponding scope middleware.

If either point is missing, admins might receive 401/403 responses.

tests/e2e/Services/Databases/DatabasesBase.php (3)

5582-5627: Well-structured transaction creation tests

The test properly covers both success and failure scenarios for transaction creation, including TTL validation boundaries.


5778-5860: Comprehensive transaction commit test

The test properly validates the transaction commit flow, including attribute creation wait time and document verification after commit.


3894-3989: Potential data integrity issue in test

The test creates documents with releaseYear and actors fields, but these attributes are never defined in the collection schema. Only the title attribute is created. This could lead to unexpected behavior or test failures if the system enforces strict schema validation.

#!/bin/bash
# Check if there are other tests in the codebase that create documents with undefined attributes
rg -A 10 -B 5 "releaseYear|actors" tests/e2e/Services/Databases/ | grep -E "(createAttribute|documents.*data)" | head -20

abnegate added 5 commits June 18, 2025 16:53
# Conflicts:
#	app/config/errors.php
#	app/config/roles.php
#	app/controllers/api/databases.php
#	composer.json
#	composer.lock
#	src/Appwrite/Extend/Exception.php
#	src/Appwrite/Utopia/Response.php
#	tests/e2e/Services/Databases/Legacy/DatabasesBase.php
Copy link

github-actions bot commented Jul 29, 2025

✨ Benchmark results

  • Requests per second: 1,282
  • Requests with 200 status code: 230,831
  • P99 latency: 0.149709866

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,282 1,015
200 230,831 182,792
P99 0.149709866 0.189337512

abnegate and others added 2 commits August 11, 2025 20:06
# Conflicts:
#	composer.json
#	composer.lock
#	tests/e2e/Services/Databases/Legacy/DatabasesBase.php
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