Skip to content

Add support for tablesdb in event generation and realtime channels#11404

Merged
abnegate merged 1 commit into1.8.xfrom
realtime-channels-tablesdb-fix
Feb 26, 2026
Merged

Add support for tablesdb in event generation and realtime channels#11404
abnegate merged 1 commit into1.8.xfrom
realtime-channels-tablesdb-fix

Conversation

@ArnabChatterjee20k
Copy link
Copy Markdown
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?

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 25, 2026

📝 Walkthrough

Walkthrough

This change adds database context awareness to event generation and realtime channel subscription logic. The Event class's generateEvents method now accepts an optional Document parameter and uses it to conditionally remap event types based on database configuration. The Realtime event handler passes database context to event generation. A new helper method in the Messaging adapter generates database-specific channel names for different API types (legacy databases and tablesdb), with backward compatibility logic to ensure both legacy and current channel naming schemes are used. A new end-to-end test validates channel subscriptions and event payloads for TablesDB operations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is a template with empty sections and no concrete details about the changes, test plan, or related issues. Fill in the description with details about what tablesdb support enables, how it was tested, and any related issues or PRs.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding tablesdb support to event generation and realtime channels, which matches the changeset's core purpose.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch realtime-channels-tablesdb-fix

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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

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

@github-actions
Copy link
Copy Markdown

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
libecpg 18.1-r0 CVE-2026-2004 HIGH
libecpg 18.1-r0 CVE-2026-2005 HIGH
libecpg 18.1-r0 CVE-2026-2006 HIGH
libecpg 18.1-r0 CVE-2026-2007 HIGH
libecpg-dev 18.1-r0 CVE-2026-2004 HIGH
libecpg-dev 18.1-r0 CVE-2026-2005 HIGH
libecpg-dev 18.1-r0 CVE-2026-2006 HIGH
libecpg-dev 18.1-r0 CVE-2026-2007 HIGH
libpng 1.6.54-r0 CVE-2026-25646 HIGH
libpng-dev 1.6.54-r0 CVE-2026-25646 HIGH
libpq 18.1-r0 CVE-2026-2004 HIGH
libpq 18.1-r0 CVE-2026-2005 HIGH
libpq 18.1-r0 CVE-2026-2006 HIGH
libpq 18.1-r0 CVE-2026-2007 HIGH
libpq-dev 18.1-r0 CVE-2026-2004 HIGH
libpq-dev 18.1-r0 CVE-2026-2005 HIGH
libpq-dev 18.1-r0 CVE-2026-2006 HIGH
libpq-dev 18.1-r0 CVE-2026-2007 HIGH
postgresql18-dev 18.1-r0 CVE-2026-2004 HIGH
postgresql18-dev 18.1-r0 CVE-2026-2005 HIGH
postgresql18-dev 18.1-r0 CVE-2026-2006 HIGH
postgresql18-dev 18.1-r0 CVE-2026-2007 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 25, 2026

🔄 PHP-Retry Summary

Flaky tests detected across commits:

Commit a57d970 - 2 flaky tests
Test Retries Total Time Details
UsageTest::testDatabaseStatsCollectionsAPI 1 10.12s Logs
RealtimeCustomClientQueryTest::testDatabaseChannelWithQuery 1 120.84s Logs

@github-actions
Copy link
Copy Markdown

✨ Benchmark results

  • Requests per second: 1,833
  • Requests with 200 status code: 330,061
  • P99 latency: 0.088736804

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,833 1,099
200 330,061 197,840
P99 0.088736804 0.185737605

Copy link
Copy Markdown
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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/Appwrite/Messaging/Adapter/Realtime.php (1)

533-535: ⚠️ Potential issue | 🔴 Critical

Fix row-security flag check for TablesDB table events.

Line 533 checks only documentSecurity, but Table objects use rowSecurity. When handling TablesDB table row events, $collection->getAttribute('documentSecurity', false) returns false (Table.php removes this attribute in favor of rowSecurity), incorrectly skipping row-level read permissions from $payload->getRead(). Update the condition to check both flags or differentiate between Collection and Table objects.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Appwrite/Messaging/Adapter/Realtime.php` around lines 533 - 535, The
current check uses $collection->getAttribute('documentSecurity', false) which
misses TablesDB tables that use rowSecurity; update the condition in the
Realtime handler (around $collection->getAttribute('documentSecurity', false))
to also check $collection->getAttribute('rowSecurity', false) (or OR the two
flags) so that when either documentSecurity or rowSecurity is true you merge
$collection->getRead() with $payload->getRead(); ensure the change still
preserves the existing behavior for non-table collections.
🧹 Nitpick comments (2)
src/Appwrite/Event/Event.php (1)

537-539: Use a root-prefix check for database remapping.

Line 537 currently uses str_contains($pattern, 'databases.'). Consider str_starts_with($pattern, 'databases.') to avoid remapping non-root patterns that merely contain that token.

💡 Suggested refinement
-        if ((str_contains($pattern, 'databases.') && $database && $database->getAttribute('type') !== 'legacy')) {
+        if ((str_starts_with($pattern, 'databases.') && $database && $database->getAttribute('type') !== 'legacy')) {
             $parsed = self::getDatabaseTypeEvents($database, $parsed);
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Appwrite/Event/Event.php` around lines 537 - 539, The conditional that
decides to remap database events currently checks str_contains($pattern,
'databases.') which can match non-root patterns; update the check in Event::
(the if using $pattern and $database) to use str_starts_with($pattern,
'databases.') so only root-prefixed patterns trigger
getDatabaseTypeEvents($database, $parsed); keep the rest of the condition and
call to self::getDatabaseTypeEvents unchanged.
tests/e2e/Services/Realtime/RealtimeCustomClientTest.php (1)

2674-2676: Assert tablesdb.* event names explicitly in this E2E case.

At Line 2675 the test only validates the databases-prefixed compatibility event. Add a tablesdb.{db}.tables.{table}.rows.{row}.create assertion so regressions in primary tablesdb event generation are caught directly.

💡 Suggested assertion addition
         // Primary event should still be present
         $this->assertContains("databases.{$databaseId}.tables.{$tableId}.rows.{$rowId}.create", $response['data']['events']);
+        $this->assertContains("tablesdb.{$databaseId}.tables.{$tableId}.rows.{$rowId}.create", $response['data']['events']);
         $this->assertNotEmpty($response['data']['payload']);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/e2e/Services/Realtime/RealtimeCustomClientTest.php` around lines 2674 -
2676, Add an explicit assertion for the tablesdb-prefixed primary event in the
RealtimeCustomClientTest so regressions are caught: in the test method where
$response, $databaseId, $tableId, and $rowId are used (around the existing
assertions that check
"databases.{$databaseId}.tables.{$tableId}.rows.{$rowId}.create" and
$response['data']['payload']), add an assertContains for the string
"tablesdb.{$databaseId}.tables.{$tableId}.rows.{$rowId}.create" against
$response['data']['events'] to ensure the
tablesdb.{db}.tables.{table}.rows.{row}.create event is present.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Appwrite/Event/Event.php`:
- Around line 727-729: The return uses array_unique($events) which preserves
numeric keys and can produce sparse arrays that serialize to JSON objects;
change the return to reindex the result so JSON encodes as an array (e.g., wrap
array_unique($events) with array_values) in the method in Event.php that
currently returns array_unique($events) so downstream consumers like
EventProcessor and Functions workers receive a proper JSON array.

---

Outside diff comments:
In `@src/Appwrite/Messaging/Adapter/Realtime.php`:
- Around line 533-535: The current check uses
$collection->getAttribute('documentSecurity', false) which misses TablesDB
tables that use rowSecurity; update the condition in the Realtime handler
(around $collection->getAttribute('documentSecurity', false)) to also check
$collection->getAttribute('rowSecurity', false) (or OR the two flags) so that
when either documentSecurity or rowSecurity is true you merge
$collection->getRead() with $payload->getRead(); ensure the change still
preserves the existing behavior for non-table collections.

---

Nitpick comments:
In `@src/Appwrite/Event/Event.php`:
- Around line 537-539: The conditional that decides to remap database events
currently checks str_contains($pattern, 'databases.') which can match non-root
patterns; update the check in Event:: (the if using $pattern and $database) to
use str_starts_with($pattern, 'databases.') so only root-prefixed patterns
trigger getDatabaseTypeEvents($database, $parsed); keep the rest of the
condition and call to self::getDatabaseTypeEvents unchanged.

In `@tests/e2e/Services/Realtime/RealtimeCustomClientTest.php`:
- Around line 2674-2676: Add an explicit assertion for the tablesdb-prefixed
primary event in the RealtimeCustomClientTest so regressions are caught: in the
test method where $response, $databaseId, $tableId, and $rowId are used (around
the existing assertions that check
"databases.{$databaseId}.tables.{$tableId}.rows.{$rowId}.create" and
$response['data']['payload']), add an assertContains for the string
"tablesdb.{$databaseId}.tables.{$tableId}.rows.{$rowId}.create" against
$response['data']['events'] to ensure the
tablesdb.{db}.tables.{table}.rows.{row}.create event is present.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5d6e43e and a57d970.

📒 Files selected for processing (4)
  • src/Appwrite/Event/Event.php
  • src/Appwrite/Event/Realtime.php
  • src/Appwrite/Messaging/Adapter/Realtime.php
  • tests/e2e/Services/Realtime/RealtimeCustomClientTest.php

@abnegate abnegate merged commit 0272a7f into 1.8.x Feb 26, 2026
232 of 235 checks passed
@abnegate abnegate deleted the realtime-channels-tablesdb-fix branch February 26, 2026 03:44
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