Skip to content

Conversation

@fogelito
Copy link
Contributor

@fogelito fogelito commented Oct 20, 2025

Summary by CodeRabbit

  • New Features

    • Adapters now expose and use database-specific maximum VARCHAR lengths, improving schema generation and attribute sizing accuracy.
  • Tests

    • End-to-end tests updated to compute and exercise attribute width limits dynamically using each adapter’s VARCHAR cap, enhancing coverage and error validation.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 20, 2025

Walkthrough

Adds an abstract getMaxVarcharLength() to the Adapter interface and implements concrete versions in MariaDB, Postgres, Mongo, and Pool; tests updated to compute varchar sizing dynamically from the adapter limit instead of hard-coded values.

Changes

Cohort / File(s) Change Summary
Adapter core / legacy
src/Database/Adapter.php, src/Database/Adapter/SQL.php
Added abstract getMaxVarcharLength(): int to the Adapter core; removed the concrete getMaxVarcharLength() implementation from SQL.php.
Adapter implementations
src/Database/Adapter/MariaDB.php, src/Database/Adapter/Postgres.php, src/Database/Adapter/Mongo.php, src/Database/Adapter/Pool.php
Added public getMaxVarcharLength(): int to each implementation: MariaDB delegates to getMaxIndexLength() (bounded), Postgres returns constant (16383), Mongo returns 0, and Pool forwards the call to its underlying adapter.
Tests — attribute/collection limits
tests/e2e/Adapter/Scopes/AttributeTests.php, tests/e2e/Adapter/Scopes/CollectionTests.php
Rewrote tests to compute limits dynamically using the adapter's getMaxVarcharLength() and document/row-size limits; replaced hard-coded varchar sizes with loops creating attributes sized to the adapter max; updated assertions, including exact exception message check in collection test.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant T as Tests
  participant S as SchemaGenerator
  participant P as Pool (optional)
  participant A as Adapter (MariaDB/Postgres/Mongo)
  note right of A #DDEEFF: Concrete adapter\nimplements getMaxVarcharLength()

  T->>S: request create attribute / collection
  S->>P: ask max varchar (if pool used)
  P-->>A: delegate getMaxVarcharLength()
  A-->>P: return maxVarcharLength
  P-->>S: forward maxVarcharLength
  S->>S: choose VARCHAR vs TEXT and compute row/document width
  alt within limits
    S-->>T: creation succeeds
  else exceeds limit
    S-->>T: throw LimitException ("Row width limit reached. Cannot create new attribute.")
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐇 I hopped through code with nimble cheer,

Replaced hard numbers, made limits clear,
Adapters now tell how wide to be,
Tests learned to ask and dance with me,
A little patch — a tidy ear!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 45.45% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Reduce varchar max length" is related to the changeset but only partially captures the main architectural change. The pull request's primary objective is to make the maximum varchar length adapter-specific by removing the base implementation from SQL.php and adding adapter-specific implementations. However, the changes show mixed results regarding actual length values: Postgres increases from 16381 to 16383, Mongo returns 0, and MariaDB delegates to index length constraints. While the title references a real and important aspect of the change (varchar length constraints), it does not fully convey the core refactoring of moving this responsibility from the base adapter class to individual implementations, nor does it accurately represent that some adapters see increased limits.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch reduce-varchar-size

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ee9b88d and 4a8dbd2.

📒 Files selected for processing (6)
  • src/Database/Adapter.php (1 hunks)
  • src/Database/Adapter/MariaDB.php (1 hunks)
  • src/Database/Adapter/Mongo.php (1 hunks)
  • src/Database/Adapter/Pool.php (1 hunks)
  • src/Database/Adapter/SQL.php (0 hunks)
  • tests/e2e/Adapter/Scopes/AttributeTests.php (5 hunks)
💤 Files with no reviewable changes (1)
  • src/Database/Adapter/SQL.php
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-10-03T02:04:17.803Z
Learnt from: abnegate
PR: utopia-php/database#721
File: tests/e2e/Adapter/Scopes/DocumentTests.php:6418-6439
Timestamp: 2025-10-03T02:04:17.803Z
Learning: In tests/e2e/Adapter/Scopes/DocumentTests::testSchemalessDocumentInvalidInteralAttributeValidation (PHP), when the adapter reports getSupportForAttributes() === false (schemaless), the test should not expect exceptions from createDocuments for “invalid” internal attributes; remove try/catch and ensure the test passes without exceptions, keeping at least one assertion.

Applied to files:

  • tests/e2e/Adapter/Scopes/AttributeTests.php
📚 Learning: 2025-10-03T01:50:11.943Z
Learnt from: abnegate
PR: utopia-php/database#721
File: tests/e2e/Adapter/Scopes/AttributeTests.php:1329-1334
Timestamp: 2025-10-03T01:50:11.943Z
Learning: MongoDB has a 1024kb (1,048,576 bytes) limit for index entries. The MongoDB adapter's getMaxIndexLength() method should return this limit rather than 0.

Applied to files:

  • src/Database/Adapter/Mongo.php
🧬 Code graph analysis (5)
src/Database/Adapter/MariaDB.php (5)
src/Database/Adapter.php (2)
  • getMaxVarcharLength (1404-1404)
  • getMaxIndexLength (876-876)
src/Database/Adapter/Mongo.php (2)
  • getMaxVarcharLength (3193-3196)
  • getMaxIndexLength (3092-3095)
src/Database/Adapter/Pool.php (2)
  • getMaxVarcharLength (613-616)
  • getMaxIndexLength (308-311)
src/Database/Adapter/Postgres.php (1)
  • getMaxVarcharLength (2328-2331)
src/Database/Adapter/SQL.php (1)
  • getMaxIndexLength (1869-1875)
tests/e2e/Adapter/Scopes/AttributeTests.php (5)
src/Database/Adapter.php (3)
  • createAttribute (557-557)
  • getDocumentSizeLimit (1173-1173)
  • getMaxVarcharLength (1404-1404)
src/Database/Adapter/SQL.php (2)
  • createAttribute (234-248)
  • getDocumentSizeLimit (1032-1035)
src/Database/Adapter/Postgres.php (2)
  • createAttribute (442-471)
  • getMaxVarcharLength (2328-2331)
src/Database/Database.php (3)
  • createAttribute (1748-1807)
  • Database (37-8363)
  • getAdapter (1251-1254)
src/Database/Adapter/MariaDB.php (1)
  • getMaxVarcharLength (1941-1948)
src/Database/Adapter/Mongo.php (4)
src/Database/Adapter.php (1)
  • getMaxVarcharLength (1404-1404)
src/Database/Adapter/MariaDB.php (1)
  • getMaxVarcharLength (1941-1948)
src/Database/Adapter/Pool.php (1)
  • getMaxVarcharLength (613-616)
src/Database/Adapter/Postgres.php (1)
  • getMaxVarcharLength (2328-2331)
src/Database/Adapter.php (4)
src/Database/Adapter/MariaDB.php (1)
  • getMaxVarcharLength (1941-1948)
src/Database/Adapter/Mongo.php (1)
  • getMaxVarcharLength (3193-3196)
src/Database/Adapter/Pool.php (1)
  • getMaxVarcharLength (613-616)
src/Database/Adapter/Postgres.php (1)
  • getMaxVarcharLength (2328-2331)
src/Database/Adapter/Pool.php (5)
src/Database/Adapter.php (1)
  • getMaxVarcharLength (1404-1404)
src/Database/Adapter/MariaDB.php (1)
  • getMaxVarcharLength (1941-1948)
src/Database/Adapter/Mongo.php (1)
  • getMaxVarcharLength (3193-3196)
src/Database/Adapter/Postgres.php (1)
  • getMaxVarcharLength (2328-2331)
src/Database/Mirror.php (1)
  • delegate (88-103)
⏰ 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). (13)
  • GitHub Check: Adapter Tests (SharedTables/Postgres)
  • GitHub Check: Adapter Tests (SharedTables/SQLite)
  • GitHub Check: Adapter Tests (SharedTables/MongoDB)
  • GitHub Check: Adapter Tests (Mirror)
  • GitHub Check: Adapter Tests (Schemaless/MongoDB)
  • GitHub Check: Adapter Tests (Postgres)
  • GitHub Check: Adapter Tests (Pool)
  • GitHub Check: Adapter Tests (MySQL)
  • GitHub Check: Adapter Tests (SharedTables/MariaDB)
  • GitHub Check: Adapter Tests (SQLite)
  • GitHub Check: Adapter Tests (MariaDB)
  • GitHub Check: Adapter Tests (SharedTables/MySQL)
  • GitHub Check: Adapter Tests (MongoDB)

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.

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

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between da0d583 and c7bd1c0.

📒 Files selected for processing (5)
  • src/Database/Adapter/MariaDB.php (1 hunks)
  • src/Database/Adapter/Postgres.php (1 hunks)
  • src/Database/Adapter/SQL.php (1 hunks)
  • tests/e2e/Adapter/Scopes/AttributeTests.php (3 hunks)
  • tests/e2e/Adapter/Scopes/CollectionTests.php (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-03T02:04:17.803Z
Learnt from: abnegate
PR: utopia-php/database#721
File: tests/e2e/Adapter/Scopes/DocumentTests.php:6418-6439
Timestamp: 2025-10-03T02:04:17.803Z
Learning: In tests/e2e/Adapter/Scopes/DocumentTests::testSchemalessDocumentInvalidInteralAttributeValidation (PHP), when the adapter reports getSupportForAttributes() === false (schemaless), the test should not expect exceptions from createDocuments for “invalid” internal attributes; remove try/catch and ensure the test passes without exceptions, keeping at least one assertion.

Applied to files:

  • tests/e2e/Adapter/Scopes/AttributeTests.php
  • tests/e2e/Adapter/Scopes/CollectionTests.php
🧬 Code graph analysis (5)
src/Database/Adapter/MariaDB.php (5)
src/Database/Adapter/Postgres.php (1)
  • getMaxVarcharLength (2328-2331)
src/Database/Adapter/SQL.php (2)
  • getMaxVarcharLength (1855-1855)
  • getMaxIndexLength (1874-1880)
src/Database/Adapter/Mongo.php (1)
  • getMaxIndexLength (3092-3095)
src/Database/Adapter.php (1)
  • getMaxIndexLength (876-876)
src/Database/Adapter/Pool.php (1)
  • getMaxIndexLength (308-311)
tests/e2e/Adapter/Scopes/AttributeTests.php (7)
src/Database/Database.php (3)
  • getAdapter (1250-1253)
  • Database (37-8357)
  • createAttribute (1747-1806)
src/Database/Adapter/SQL.php (3)
  • getDocumentSizeLimit (1032-1035)
  • getMaxVarcharLength (1855-1855)
  • createAttribute (234-248)
src/Database/Adapter/Mongo.php (2)
  • getDocumentSizeLimit (2843-2846)
  • createAttribute (665-668)
src/Database/Adapter.php (2)
  • getDocumentSizeLimit (1173-1173)
  • createAttribute (557-557)
src/Database/Adapter/Pool.php (2)
  • getDocumentSizeLimit (468-471)
  • createAttribute (168-171)
src/Database/Adapter/MariaDB.php (1)
  • getMaxVarcharLength (1941-1945)
src/Database/Adapter/Postgres.php (2)
  • getMaxVarcharLength (2328-2331)
  • createAttribute (442-471)
tests/e2e/Adapter/Scopes/CollectionTests.php (3)
src/Database/Database.php (3)
  • getAdapter (1250-1253)
  • createAttribute (1747-1806)
  • Database (37-8357)
src/Database/Adapter/SQL.php (3)
  • getDocumentSizeLimit (1032-1035)
  • getMaxVarcharLength (1855-1855)
  • createAttribute (234-248)
src/Database/Adapter.php (2)
  • getDocumentSizeLimit (1173-1173)
  • createAttribute (557-557)
src/Database/Adapter/SQL.php (2)
src/Database/Adapter/MariaDB.php (1)
  • getMaxVarcharLength (1941-1945)
src/Database/Adapter/Postgres.php (1)
  • getMaxVarcharLength (2328-2331)
src/Database/Adapter/Postgres.php (2)
src/Database/Adapter/MariaDB.php (1)
  • getMaxVarcharLength (1941-1945)
src/Database/Adapter/SQL.php (1)
  • getMaxVarcharLength (1855-1855)
🪛 GitHub Actions: CodeQL
src/Database/Adapter/MariaDB.php

[error] 1944-1944: Unreachable statement - code above always terminates.

tests/e2e/Adapter/Scopes/AttributeTests.php

[error] 982-982: Call to an undefined method Utopia\Database\Adapter::getMaxVarcharLength().


[error] 990-990: Call to an undefined method Utopia\Database\Adapter::getMaxVarcharLength().


[error] 1002-1002: Call to an undefined method Utopia\Database\Adapter::getMaxVarcharLength().


[error] 1029-1029: Call to an undefined method Utopia\Database\Adapter::getMaxVarcharLength().


[error] 1046-1046: Call to an undefined method Utopia\Database\Adapter::getMaxVarcharLength().

tests/e2e/Adapter/Scopes/CollectionTests.php

[error] 609-609: Call to an undefined method Utopia\Database\Adapter::getMaxVarcharLength().


[error] 612-612: Call to an undefined method Utopia\Database\Adapter::getMaxVarcharLength().


[error] 616-616: Call to an undefined method Utopia\Database\Adapter::getMaxVarcharLength().

⏰ 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 (1)
tests/e2e/Adapter/Scopes/AttributeTests.php (1)

982-1046: ****

The original concern is based on incomplete analysis. While getMaxVarcharLength() is indeed missing from the Mongo and Pool adapters, the test is protected by a guard condition that prevents runtime failures:

  1. Mongo adapter: Returns 0 from getDocumentSizeLimit() (line 2845), causing the test to skip with early return (line 977-980)
  2. Pool adapter: Delegates to underlying adapters—in practice only MariaDB/Postgres, both of which implement getMaxVarcharLength()
  3. SQL-extending adapters: MariaDB and Postgres both implement getMaxVarcharLength() and have non-zero document size limits, so the test executes normally

The implementation is complete and correct. Pipeline failures are likely static analysis limitations rather than actual runtime issues.

Likely an incorrect or invalid review comment.

@fogelito
Copy link
Contributor Author

fogelito commented Oct 20, 2025

We need to check this PR on Appwrite before merge

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