Skip to content

Big int#847

Draft
ArnabChatterjee20k wants to merge 30 commits intomainfrom
big-init
Draft

Big int#847
ArnabChatterjee20k wants to merge 30 commits intomainfrom
big-init

Conversation

@ArnabChatterjee20k
Copy link
Copy Markdown
Contributor

@ArnabChatterjee20k ArnabChatterjee20k commented Mar 27, 2026

Summary by CodeRabbit

  • New Features
    • Added support for a BIGINT attribute type for 64-bit signed/unsigned integer storage and consistent handling across adapters and queries.
  • Bug Fixes
    • Improved type mapping and validation so bigint values are stored, cast, and queried reliably and size accounting is adjusted where applicable.
  • Tests
    • Added unit and end-to-end tests covering BIGINT attribute creation, validation, document operations, increments/decrements, and boundary values.

…BigInt method

- Added abstract method getLimitForBigInt to Adapter class.
- Implemented getLimitForBigInt in Mongo, Pool, and SQL classes.
- Updated MariaDB and Postgres adapters to handle VAR_BIGINT type.
- Enhanced error messages for unknown types to include VAR_BIGINT.
- Introduced VAR_BIGINT constant in Database class.
- Updated Attribute class to include maxBigIntLength parameter and handle it in validation.
- Ensured backwards compatibility for existing validator construction.
- Enhanced validation logic to enforce size limits for VAR_BIGINT type.
- Introduced testCreateAttributesBigIntSizeLimit to verify exception handling for oversized BIGINT attributes.
- Added testCreateDocumentWithBigIntType to ensure correct document creation and retrieval with BIGINT attributes.
- Implemented testBigIntSizeTooLarge and testUnsignedBigIntSizeLimit to validate size constraints in the Attribute validator.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 27, 2026

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.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e9c25125-48e7-4a74-b64b-4ed783c980e1

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

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds VAR_BIGINT support across the database layer: new adapter accessor, SQL/MariaDB/Postgres and Mongo mappings, validator updates for bigint sizing and validation, Database constant and attribute wiring, Pool delegation, and new unit and e2e tests for bigint behavior.

Changes

Cohort / File(s) Summary
Adapter API & Core
src/Database/Adapter.php, src/Database/Database.php
Added abstract getLimitForBigInt() to Adapter; introduced Database::VAR_BIGINT and threaded bigint limit into attribute construction/validation.
SQL Layer & Pool
src/Database/Adapter/SQL.php, src/Database/Adapter/Pool.php
Implemented getLimitForBigInt() in SQL and Pool; attribute width estimation updated to include VAR_BIGINT (+8 bytes).
Relational Adapters
src/Database/Adapter/MariaDB.php, src/Database/Adapter/Postgres.php
Added explicit VAR_BIGINT handling in getSQLType() returning BIGINT (with optional UNSIGNED); updated unsupported-type error message to include VAR_BIGINT.
Mongo Adapter
src/Database/Adapter/Mongo.php
Mapped VAR_BIGINT to MongoDB long in getMongoTypeCode(), cast bigint values in castingAfter(), and added getLimitForBigInt().
Validators
src/Database/Validator/Attribute.php, src/Database/Validator/Query/Filter.php, src/Database/Validator/Structure.php
Added maxBigIntLength constructor parameter and fallback; added VAR_BIGINT handling branches; integer bit-width logic updated so VAR_BIGINT forces 64-bit validation.
Tests
tests/unit/Validator/AttributeTest.php, tests/e2e/Adapter/Scopes/AttributeTests.php, tests/e2e/Adapter/Scopes/DocumentTests.php
Added unit tests for bigint attribute size behavior and e2e tests for attribute creation, document storage/retrieval, updates, and atomic inc/dec operations using VAR_BIGINT.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • Feat mongodb #721 — Extends adapter surface and MongoDB adapter capabilities; overlaps on adapter/API and bigint-related changes.
  • Feat mongodb #731 — Modifies adapter classes and Mongo support; touches similar adapter implementations and mappings.

Suggested reviewers

  • abnegate
  • fogelito

Poem

🐰 I found a bigint in the hay,

Eight bytes more to hop and play,
Signed, unsigned, stored with care,
Validators nibble here and there,
Hooray for numbers that can stay.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Big int' is vague and generic, using non-descriptive language that doesn't convey meaningful information about the changeset, such as what is being added or changed. Consider a more descriptive title like 'Add BIGINT type support to database adapters' or 'Implement VAR_BIGINT attribute type with 64-bit integer handling' to better summarize the primary changes.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch big-init

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.

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 27, 2026

Greptile Summary

This PR adds VAR_BIGINT as a first-class 64-bit integer type across all database adapters (MariaDB, Postgres, SQLite, MongoDB) and the validation layer. The implementation is well-structured — a new BigInt helper performs string-based arithmetic to safely represent values beyond PHP_INT_MAX, and a new BigInt validator handles both PHP-native integers and numeric strings. The SQL and Postgres adapters look correct; getLimitForBigInt() in SQL.php now correctly returns Database::MAX_BIG_INT (PHP_INT_MAX), addressing the overflow issue from previous review rounds.

Three issues remain that need attention before merge:

  • Default value validation is too strict (Attribute.php line 555, Database.php line 2633): Both checks require $defaultType === 'integer', but any bigint default exceeding PHP_INT_MAX must be provided as a PHP string. gettype() on a string returns 'string', so all such defaults are silently rejected — even though the BigInt::isValid() validator accepts strings correctly.
  • Mongo decode path truncates large bigints (Mongo.php line 1322–1323): VAR_BIGINT falls through the case Database::VAR_INTEGER: cast to (int)$node, silently truncating values above PHP_INT_MAX on round-trip from MongoDB. Database.php's own cast path already does this correctly with BigIntHelper::fitsPhpInt().
  • Duplicate VAR_BIGINT in error message (Attribute.php lines 450–451): Database::VAR_BIGINT appears twice in the $supportedTypes array used to build the "Unknown attribute type" message.

Confidence Score: 4/5

Two P1 bugs — default value validation rejecting valid string bigints, and Mongo silently truncating large values on decode — should be fixed before merging.

The core bigint plumbing (helper, validator, SQL adapters) is solid and the previous overflow concern in getLimitForBigInt() has been resolved. However, two P1 correctness bugs remain: (1) setting a bigint default > PHP_INT_MAX is impossible due to the overly-strict type check, and (2) MongoDB round-trips silently corrupt large bigint values via the (int) cast.

src/Database/Adapter/Mongo.php (decode truncation) and src/Database/Validator/Attribute.php / src/Database/Database.php (default value type check)

Vulnerabilities

No security concerns identified. The string-based arithmetic in BigIntHelper avoids integer overflow, and no user-supplied values are used in raw SQL construction for the new type.

Important Files Changed

Filename Overview
src/Database/Helpers/BigInt.php New helper class with string-based arithmetic for safe 64-bit integer operations beyond PHP_INT_MAX; implementation looks correct.
src/Database/Validator/BigInt.php New validator accepting both PHP int and numeric strings for signed/unsigned 64-bit ranges; correctly delegates to BigIntHelper.
src/Database/Validator/Attribute.php Adds BIGINT attribute validation, but has two bugs: (1) duplicate VAR_BIGINT entry in supported-types error message, and (2) default value check rejects string bigints, blocking any default > PHP_INT_MAX.
src/Database/Adapter/Mongo.php Maps VAR_BIGINT to MongoDB 'long' type correctly, but the decode path casts all BIGINT values with (int), silently truncating any value above PHP_INT_MAX.
src/Database/Validator/Query/Filter.php Adds BigInt validator for filter queries; dead condition $attributeType === Database::VAR_BIGINT inside the VAR_INTEGER case is unreachable.
src/Database/Database.php VAR_BIGINT wired through create/update/cast paths; default value type check at line 2633 has the same string-rejection bug as Attribute.php.
src/Database/Adapter/SQL.php getLimitForBigInt() correctly returns Database::MAX_BIG_INT (PHP_INT_MAX); row-size accounting correctly adds 8 bytes for BIGINT columns.
src/Database/Adapter/MariaDB.php Adds BIGINT SQL type mapping with optional UNSIGNED; enables getSupportForUnsignedBigInt(); looks correct.
src/Database/Adapter/Postgres.php Maps VAR_BIGINT to BIGINT SQL type; Postgres doesn't support unsigned integers so unsigned flag is intentionally absent.
src/Database/Adapter/SQLite.php Maps VAR_BIGINT to INTEGER for SQLite (appropriate since SQLite uses dynamic typing).
src/Database/Validator/Structure.php Correctly normalises BIGINT string values within PHP int range and uses BigInt validator; looks solid.

Reviews (3): Last reviewed commit: "updated" | Re-trigger Greptile

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

Caution

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

⚠️ Outside diff range comments (1)
src/Database/Validator/Attribute.php (1)

521-545: ⚠️ Potential issue | 🟠 Major

Missing VAR_BIGINT case in validateDefaultTypes() will cause default value validation to fail.

The validateDefaultTypes() method doesn't handle Database::VAR_BIGINT. When a bigint attribute has a default value set, it will fall through to the default case and throw an "Unknown attribute type" exception.

Since bigint should support integer default values (same as VAR_INTEGER), add a case for it.

🐛 Proposed fix
             case Database::VAR_INTEGER:
+            case Database::VAR_BIGINT:
             case Database::VAR_FLOAT:
             case Database::VAR_BOOLEAN:
                 if ($type !== $defaultType) {

Note: This assumes bigint default values should be validated as PHP integers. However, since bigint can exceed PHP's PHP_INT_MAX on 32-bit systems, you may want to also accept string representations. Verify the intended behavior.

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

In `@src/Database/Validator/Attribute.php` around lines 521 - 545, The switch in
validateDefaultTypes() is missing Database::VAR_BIGINT so bigint defaults fall
through to the default error; add Database::VAR_BIGINT to the same case group
that contains Database::VAR_INTEGER (i.e., the branch that validates
numeric/boolean defaults) so bigint default values are validated like integers;
ensure the added case label appears alongside
Database::VAR_INTEGER/VAR_FLOAT/VAR_BOOLEAN in
Attribute::validateDefaultTypes().
🧹 Nitpick comments (2)
src/Database/Adapter/Postgres.php (1)

2001-2001: Keep the supported-types exception list centralized.

The supported-type list in this exception is still hardcoded and easy to desync from switch cases. Consider deriving it from a shared constant/list to avoid future drift.

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

In `@src/Database/Adapter/Postgres.php` at line 2001, The throw in Postgres (the
DatabaseException with the long hardcoded VAR_* list) must use a single
authoritative source of supported types instead of duplicating them; add or use
an existing Database::SUPPORTED_TYPES (or Database::getSupportedTypes())
constant/static method that returns the array of supported VAR_* values, and
change the exception construction in Postgres to build the message from that
array (e.g., implode(', ', Database::SUPPORTED_TYPES)) so the list is derived
from the shared constant; update the throw site that currently references
DatabaseException and the VAR_* names to use that shared symbol.
src/Database/Validator/Attribute.php (1)

431-451: Consider adding VAR_BIGINT to the supported types list for accurate error messages.

When an unknown type is passed, the error message lists supported types but omits VAR_BIGINT. While this won't cause functional issues (since BIGINT is handled above), adding it would make error messages more accurate.

♻️ Suggested improvement
             default:
                 $supportedTypes = [
                     Database::VAR_STRING,
                     Database::VAR_VARCHAR,
                     Database::VAR_TEXT,
                     Database::VAR_MEDIUMTEXT,
                     Database::VAR_LONGTEXT,
                     Database::VAR_INTEGER,
+                    Database::VAR_BIGINT,
                     Database::VAR_FLOAT,
                     Database::VAR_BOOLEAN,
                     Database::VAR_DATETIME,
                     Database::VAR_RELATIONSHIP
                 ];

The same addition should be made in validateDefaultTypes() around line 554.

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

In `@src/Database/Validator/Attribute.php` around lines 431 - 451, The
supported-types array built in Attribute (the $supportedTypes list in the code
path that checks supportForVectors/supportForSpatialAttributes/supportForObject)
is missing Database::VAR_BIGINT, so update that array to include
Database::VAR_BIGINT; also make the same addition in the validateDefaultTypes()
method where a similar $supportedTypes list is constructed so error messages
consistently include VAR_BIGINT. Ensure you reference Database::VAR_BIGINT when
adding it to both $supportedTypes arrays.
🤖 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/Database/Adapter/MariaDB.php`:
- Around line 1728-1734: VAR_INTEGER was changed to map to INT causing
overflow/regression for callers expecting bigint behavior; revert or preserve
the legacy mapping by making Database::VAR_INTEGER return BIGINT semantics in
MariaDB.php (where the switch handles Database::VAR_INTEGER) or else migrate all
callers to use Database::VAR_BIGINT first. Update the case for
Database::VAR_INTEGER in the MariaDB Adapter so it produces the same BIGINT (and
UNSIGNED handling) as the Database::VAR_BIGINT case (or add a clear migration
TODO and failing assertion in callers like the tests referenced) to avoid
changing runtime column size semantics.

In `@src/Database/Adapter/Mongo.php`:
- Around line 3014-3018: The method getLimitForBigInt currently returns a
numeric literal that exceeds PHP_INT_MAX which breaks the declared return type;
update getLimitForBigInt to return the existing constant Database::MAX_BIG_INT
(or cast that constant to int if necessary) instead of the large literal
18446744073709551615 so the return value is a valid int and consistent with the
rest of the codebase.
- Line 2215: The BSON type mapping for BIGINT in the Database::VAR_BIGINT entry
is incorrect: change its value from 'int' to 'long' so that
partialFilterExpression and sparse/partial indexes use MongoDB 64-bit long type
instead of 32-bit int; locate the mapping array (the place that defines
Database::VAR_BIGINT => 'int') in the Mongo adapter (class/method that builds
type mappings or partialFilterExpression) and update that entry to 'long' so
BIGINT documents are correctly matched by $type checks.

In `@src/Database/Adapter/SQL.php`:
- Around line 904-909: The method getLimitForBigInt currently returns the
unsigned 64-bit literal 18446744073709551615 which exceeds PHP's signed 64-bit
int range and becomes a float; change the return to the signed 64-bit maximum
9223372036854775807 (as an int) so the return value matches the declared int
return type and the tests (DocumentTests.php) expectations; update the return
expression in getLimitForBigInt to use 9223372036854775807 (or cast to int if
needed) to ensure phpstan type checks pass.

In `@src/Database/Database.php`:
- Line 45: You added the new constant Database::VAR_BIGINT but the update and
default-validation code still treat 'bigint' as unknown; update the
type-handling in updateAttribute() and validateDefaultTypes() to recognize
self::VAR_BIGINT (or 'bigint') where other integer-like types are handled (e.g.,
the switch/case or type-to-validator map), and ensure the default/type coercion
paths treat bigint the same as other integer types so updates and default
validation accept bigint attributes.

---

Outside diff comments:
In `@src/Database/Validator/Attribute.php`:
- Around line 521-545: The switch in validateDefaultTypes() is missing
Database::VAR_BIGINT so bigint defaults fall through to the default error; add
Database::VAR_BIGINT to the same case group that contains Database::VAR_INTEGER
(i.e., the branch that validates numeric/boolean defaults) so bigint default
values are validated like integers; ensure the added case label appears
alongside Database::VAR_INTEGER/VAR_FLOAT/VAR_BOOLEAN in
Attribute::validateDefaultTypes().

---

Nitpick comments:
In `@src/Database/Adapter/Postgres.php`:
- Line 2001: The throw in Postgres (the DatabaseException with the long
hardcoded VAR_* list) must use a single authoritative source of supported types
instead of duplicating them; add or use an existing Database::SUPPORTED_TYPES
(or Database::getSupportedTypes()) constant/static method that returns the array
of supported VAR_* values, and change the exception construction in Postgres to
build the message from that array (e.g., implode(', ',
Database::SUPPORTED_TYPES)) so the list is derived from the shared constant;
update the throw site that currently references DatabaseException and the VAR_*
names to use that shared symbol.

In `@src/Database/Validator/Attribute.php`:
- Around line 431-451: The supported-types array built in Attribute (the
$supportedTypes list in the code path that checks
supportForVectors/supportForSpatialAttributes/supportForObject) is missing
Database::VAR_BIGINT, so update that array to include Database::VAR_BIGINT; also
make the same addition in the validateDefaultTypes() method where a similar
$supportedTypes list is constructed so error messages consistently include
VAR_BIGINT. Ensure you reference Database::VAR_BIGINT when adding it to both
$supportedTypes arrays.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 87c67b39-b15b-4568-84ae-ed02167caa45

📥 Commits

Reviewing files that changed from the base of the PR and between 2955d60 and b5c7447.

📒 Files selected for processing (11)
  • src/Database/Adapter.php
  • src/Database/Adapter/MariaDB.php
  • src/Database/Adapter/Mongo.php
  • src/Database/Adapter/Pool.php
  • src/Database/Adapter/Postgres.php
  • src/Database/Adapter/SQL.php
  • src/Database/Database.php
  • src/Database/Validator/Attribute.php
  • tests/e2e/Adapter/Scopes/AttributeTests.php
  • tests/e2e/Adapter/Scopes/DocumentTests.php
  • tests/unit/Validator/AttributeTest.php

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

🤖 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/Database/Adapter/SQL.php`:
- Around line 899-910: Update the PHPDoc for the getLimitForBigInt method to
match its declared return type string: replace the incorrect "@return float|int"
with "@return string" in the PHPDoc block for the getLimitForBigInt() method so
static analysis (PHPStan) stops flagging the mismatch.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 7545bd28-951f-49ea-b69e-8055e16fd3db

📥 Commits

Reviewing files that changed from the base of the PR and between b5c7447 and 8b93b40.

📒 Files selected for processing (6)
  • Dockerfile
  • src/Database/Adapter.php
  • src/Database/Adapter/Mongo.php
  • src/Database/Adapter/Pool.php
  • src/Database/Adapter/SQL.php
  • src/Database/Validator/Attribute.php
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/Database/Adapter/Pool.php
  • src/Database/Validator/Attribute.php
  • src/Database/Adapter/Mongo.php

…L adapters

- Adjusted the getLimitForBigInt method in both Mongo and SQL classes to return 4294967295, reflecting the maximum value for a 32-bit unsigned integer.
- Updated comments to clarify the handling of integer limits in PHP.
- Updated MariaDB adapter to return 'BIGINT' for sizes greater than or equal to 8 bytes.
- Modified SQL adapter to correctly calculate total size for VAR_INTEGER based on the attribute size, distinguishing between INT and BIGINT.
// 2^64 - 1
// 18446744073709551615 is the maximum value for a 64-bit unsigned integer
// 9223372036854775807 is the maximum value for a 64-bit signed integer
// in php we can't represent 64-bit integer, so greater than 4294967295 will be treated as bigint
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@abnegate in php no option for representing a bigint in form of int so having 18446744073709551615 we need to consider string for precision but we can't store the size incoming from user inside the metadata as it will be string and we have to start taking input as string
Shall we go forward with string ? or BIGINT will be marking in the table only?

- Included VAR_BIGINT in the list of attribute types in the Database class.
- Ensured consistency in handling BIGINT attributes across the database implementation.
- Added handling for VAR_BIGINT in the size limit validation logic.
- Implemented exception throwing for oversized BIGINT attributes to ensure proper error handling.
- Updated validation logic to correctly determine bit size for VAR_BIGINT and VAR_INTEGER based on attribute size.
- Ensured consistent handling of signed and unsigned integers across both validators.
- Updated Postgres adapter to return 'BIGINT' for sizes greater than or equal to 8 bytes in the type determination logic for VAR_INTEGER.
- Ensured consistent handling of integer types across the database implementation.
@ArnabChatterjee20k ArnabChatterjee20k changed the title Big init Big int Mar 27, 2026
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: 2

Caution

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

⚠️ Outside diff range comments (1)
src/Database/Database.php (1)

2586-2593: ⚠️ Potential issue | 🟠 Major

bigint defaults will always fail this type check.

PHP reports integer values as integer, not bigint, so if ($type !== $defaultType) rejects every non-null bigint default. That breaks bigint defaults in attribute create/update flows.

💡 Minimal fix
             case self::VAR_INTEGER:
             case self::VAR_BIGINT:
+                if ($defaultType !== 'integer') {
+                    throw new DatabaseException('Default value ' . $default . ' does not match given type ' . $type);
+                }
+                break;
             case self::VAR_FLOAT:
             case self::VAR_BOOLEAN:
                 if ($type !== $defaultType) {
                     throw new DatabaseException('Default value ' . $default . ' does not match given type ' . $type);
                 }
                 break;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Database/Database.php` around lines 2586 - 2593, The type check in the
block handling self::VAR_INTEGER, self::VAR_BIGINT, self::VAR_FLOAT,
self::VAR_BOOLEAN incorrectly rejects bigint defaults because PHP reports them
as "integer" (so $defaultType != $type); update the condition in the switch
branch that throws DatabaseException to accept an integer-typed default when the
target $type is self::VAR_BIGINT (i.e., treat $defaultType === 'integer' as
valid for self::VAR_BIGINT) while preserving the existing strict check for other
types; locate and modify the comparison around $type, $defaultType in the method
where the switch uses constants VAR_INTEGER/VAR_BIGINT/VAR_FLOAT/VAR_BOOLEAN and
DatabaseException is thrown.
♻️ Duplicate comments (1)
src/Database/Adapter/Mongo.php (1)

3014-3018: ⚠️ Potential issue | 🟠 Major

BIGINT limit is still capped to INT-level range.

Line 3017 returns 4294967295, which matches getLimitForInt() and removes practical headroom for BIGINT in adapter-level size-limit checks.

🔧 Proposed fix
 public function getLimitForBigInt(): int
 {
-    // Mongo does not handle integers directly, so using MariaDB limit for now
-    return 4294967295;
+    return Database::MAX_BIG_INT;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Database/Adapter/Mongo.php` around lines 3014 - 3018, getLimitForBigInt()
currently returns 4294967295 (same as getLimitForInt()), removing HEADROOM for
BIGINT checks; change getLimitForBigInt() to return the appropriate 64-bit
BIGINT max (use 9223372036854775807 to fit the method's int return type on
64-bit builds) so adapter-level size-limit checks reflect BIGINT capacity rather
than INT capacity.
🤖 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/Database/Adapter/SQL.php`:
- Around line 904-911: The getLimitForBigInt() currently returns 4294967295
(same as getLimitForInt()), so update it to return the correct BIGINT ceiling
(use 9223372036854775807 for signed 64-bit) and/or fall back to PHP_INT_MAX when
appropriate; modify getLimitForBigInt() to return 9223372036854775807 (or
PHP_INT_MAX on platforms where that better represents the native integer max) so
BIGINT checks differ from getLimitForInt().

In `@src/Database/Database.php`:
- Line 45: The atomic counter helpers increaseDocumentAttribute() and
decreaseDocumentAttribute() reject schema-backed bigint attributes because the
whitelist only permits VAR_INTEGER and VAR_FLOAT; update both functions to also
allow the class constant VAR_BIGINT (public const VAR_BIGINT) alongside
VAR_INTEGER and VAR_FLOAT so that schema attributes typed as bigint do not throw
the TypeException—locate the type-check/whitelist logic in
increaseDocumentAttribute() and decreaseDocumentAttribute() and add
self::VAR_BIGINT to the allowed types.

---

Outside diff comments:
In `@src/Database/Database.php`:
- Around line 2586-2593: The type check in the block handling self::VAR_INTEGER,
self::VAR_BIGINT, self::VAR_FLOAT, self::VAR_BOOLEAN incorrectly rejects bigint
defaults because PHP reports them as "integer" (so $defaultType != $type);
update the condition in the switch branch that throws DatabaseException to
accept an integer-typed default when the target $type is self::VAR_BIGINT (i.e.,
treat $defaultType === 'integer' as valid for self::VAR_BIGINT) while preserving
the existing strict check for other types; locate and modify the comparison
around $type, $defaultType in the method where the switch uses constants
VAR_INTEGER/VAR_BIGINT/VAR_FLOAT/VAR_BOOLEAN and DatabaseException is thrown.

---

Duplicate comments:
In `@src/Database/Adapter/Mongo.php`:
- Around line 3014-3018: getLimitForBigInt() currently returns 4294967295 (same
as getLimitForInt()), removing HEADROOM for BIGINT checks; change
getLimitForBigInt() to return the appropriate 64-bit BIGINT max (use
9223372036854775807 to fit the method's int return type on 64-bit builds) so
adapter-level size-limit checks reflect BIGINT capacity rather than INT
capacity.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f6553440-657b-4297-a48a-4c928fd82932

📥 Commits

Reviewing files that changed from the base of the PR and between 8b93b40 and 14828d9.

📒 Files selected for processing (7)
  • src/Database/Adapter/MariaDB.php
  • src/Database/Adapter/Mongo.php
  • src/Database/Adapter/Postgres.php
  • src/Database/Adapter/SQL.php
  • src/Database/Database.php
  • src/Database/Validator/Query/Filter.php
  • src/Database/Validator/Structure.php
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/Database/Adapter/Postgres.php
  • src/Database/Adapter/MariaDB.php

$attributes = [[
'$id' => 'foo',
'type' => Database::VAR_BIGINT,
'size' => (int)$limit + 1,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we can ignore size altogether for big int, doesn't make much sense. We only need to validate it's a whole number

- Eliminated size limit checks for VAR_BIGINT in the Database and Attribute classes to allow larger values.
- Updated Mongo and SQL adapters to return a constant for BIGINT limits, ensuring consistent handling across implementations.
- Refactored tests to reflect the removal of size constraints and validate successful attribute creation without exceptions.
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.

Caution

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

⚠️ Outside diff range comments (1)
src/Database/Validator/Attribute.php (1)

527-534: ⚠️ Potential issue | 🔴 Critical

Missing VAR_BIGINT case in validateDefaultTypes() will reject valid bigint defaults.

The validateDefaultTypes() method does not handle Database::VAR_BIGINT. If a bigint attribute is created with a default value, validation will fall through to the default case (line 548) and throw "Unknown attribute type", even though the type is valid.

🐛 Proposed fix
             case Database::VAR_INTEGER:
+            case Database::VAR_BIGINT:
             case Database::VAR_FLOAT:
             case Database::VAR_BOOLEAN:
                 if ($type !== $defaultType) {

Also update the $supportedTypes array in the same method (lines 549-560):

 $supportedTypes = [
     Database::VAR_STRING,
     Database::VAR_VARCHAR,
     Database::VAR_TEXT,
     Database::VAR_MEDIUMTEXT,
     Database::VAR_LONGTEXT,
     Database::VAR_INTEGER,
+    Database::VAR_BIGINT,
     Database::VAR_FLOAT,
     Database::VAR_BOOLEAN,
     Database::VAR_DATETIME,
     Database::VAR_RELATIONSHIP
 ];
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Database/Validator/Attribute.php` around lines 527 - 534,
validateDefaultTypes() currently omits Database::VAR_BIGINT so bigint defaults
fall through and trigger the "Unknown attribute type" error; add a case for
Database::VAR_BIGINT alongside Database::VAR_INTEGER/VAR_FLOAT/VAR_BOOLEAN in
the switch block inside validateDefaultTypes() so bigint default type checks use
the same logic, and also include Database::VAR_BIGINT in the $supportedTypes
array used by validateDefaultTypes() to avoid rejecting valid bigint attributes
(refer to the validateDefaultTypes() method and the $supportedTypes variable).
🧹 Nitpick comments (1)
src/Database/Validator/Attribute.php (1)

347-349: Consider adding VAR_BIGINT to $supportedTypes in the default case for error message completeness.

The empty case correctly skips size validation per design. However, VAR_BIGINT is missing from the $supportedTypes array at lines 426-446. While the explicit case prevents reaching the default, adding it to $supportedTypes ensures accurate error messages if future refactoring changes the switch structure.

♻️ Suggested addition
 $supportedTypes = [
     Database::VAR_STRING,
     Database::VAR_VARCHAR,
     Database::VAR_TEXT,
     Database::VAR_MEDIUMTEXT,
     Database::VAR_LONGTEXT,
     Database::VAR_INTEGER,
+    Database::VAR_BIGINT,
     Database::VAR_FLOAT,
     Database::VAR_BOOLEAN,
     Database::VAR_DATETIME,
     Database::VAR_RELATIONSHIP
 ];
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Database/Validator/Attribute.php` around lines 347 - 349, Add
Database::VAR_BIGINT to the $supportedTypes array used in the default-case error
message to keep the supported-types list accurate; locate the $supportedTypes
definition in the Attribute validator (variable name $supportedTypes) and append
Database::VAR_BIGINT so that error messages remain correct if the switch in
validateSize (the case Database::VAR_BIGINT) is refactored later.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/Database/Validator/Attribute.php`:
- Around line 527-534: validateDefaultTypes() currently omits
Database::VAR_BIGINT so bigint defaults fall through and trigger the "Unknown
attribute type" error; add a case for Database::VAR_BIGINT alongside
Database::VAR_INTEGER/VAR_FLOAT/VAR_BOOLEAN in the switch block inside
validateDefaultTypes() so bigint default type checks use the same logic, and
also include Database::VAR_BIGINT in the $supportedTypes array used by
validateDefaultTypes() to avoid rejecting valid bigint attributes (refer to the
validateDefaultTypes() method and the $supportedTypes variable).

---

Nitpick comments:
In `@src/Database/Validator/Attribute.php`:
- Around line 347-349: Add Database::VAR_BIGINT to the $supportedTypes array
used in the default-case error message to keep the supported-types list
accurate; locate the $supportedTypes definition in the Attribute validator
(variable name $supportedTypes) and append Database::VAR_BIGINT so that error
messages remain correct if the switch in validateSize (the case
Database::VAR_BIGINT) is refactored later.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 781931a2-1bf3-4b5b-a684-47ed567802ae

📥 Commits

Reviewing files that changed from the base of the PR and between 14828d9 and 080de0e.

📒 Files selected for processing (6)
  • src/Database/Adapter/Mongo.php
  • src/Database/Adapter/SQL.php
  • src/Database/Database.php
  • src/Database/Validator/Attribute.php
  • tests/e2e/Adapter/Scopes/AttributeTests.php
  • tests/unit/Validator/AttributeTest.php
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/Database/Adapter/SQL.php
  • tests/unit/Validator/AttributeTest.php
  • src/Database/Adapter/Mongo.php
  • src/Database/Database.php

- Included VAR_BIGINT in the whitelist for attribute types in the Database class.
- Implemented a new test to validate the creation, updating, and atomic operations for BIGINT attributes in the DocumentTests.
- Ensured that the new tests confirm correct behavior for incrementing and decrementing BIGINT values.
…tors

- Introduced `getSupportForUnsignedBigInt` method in `Adapter`, `MariaDB`, and `SQLite` classes to indicate support for unsigned big integers.
- Implemented normalization of attribute sizes for `bigint` types in the `Database` class.
- Added `BigInt` helper class for managing big integer validation and formatting.
- Updated `Attribute`, `Structure`, and `Filter` validators to handle signed and unsigned big integers correctly.
- Enhanced tests to cover scenarios for creating and validating attributes with big integers, including edge cases for signed and unsigned values.
return false;
}

public function getSupportForUnsignedBigInt(): bool
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

mongodb, postgresql, sqlite doesn't support unsigned bigint

*/
public function getLimitForBigInt(): int
{
return Database::MAX_BIG_INT;
Copy link
Copy Markdown
Contributor Author

@ArnabChatterjee20k ArnabChatterjee20k Apr 8, 2026

Choose a reason for hiding this comment

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

Here going other way around
It is the signed big int limit(supported by all adapter)
For adapters supporting unsigned int, in the attribute validator, we are validating via string comparison

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 8, 2026

Tip:

Greploops — Automatically fix all review issues by running /greploops in Claude Code. It iterates: fix, push, re-review, repeat until 5/5 confidence.

Use the Greptile plugin for Claude Code to query reviews, search comments, and manage custom context directly from your terminal.

Comment on lines +554 to +558
case Database::VAR_BIGINT:
if ($defaultType !== 'integer') {
$this->message = 'Default value ' . $default . ' does not match given type ' . $type;
throw new DatabaseException($this->message);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Default value validation blocks valid string bigints

The check $defaultType !== 'integer' only accepts PHP-native int values, but any bigint default larger than PHP_INT_MAX (e.g. "9223372036854775808" for unsigned) must be passed as a string — which gettype() returns as 'string', not 'integer'. This means it's impossible to set a valid bigint default that exceeds PHP's integer range, even though the BigInt value validator (BigInt::isValid()) explicitly accepts strings.

The same issue exists in src/Database/Database.php at line 2633.

The check should accept both PHP integers and numeric strings:

Suggested change
case Database::VAR_BIGINT:
if ($defaultType !== 'integer') {
$this->message = 'Default value ' . $default . ' does not match given type ' . $type;
throw new DatabaseException($this->message);
}
case Database::VAR_BIGINT:
if ($defaultType !== 'integer' && $defaultType !== 'string') {
$this->message = 'Default value ' . $default . ' does not match given type ' . $type;
throw new DatabaseException($this->message);
}
break;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ArnabChatterjee20k Seems valid?

Copy link
Copy Markdown
Contributor Author

@ArnabChatterjee20k ArnabChatterjee20k Apr 9, 2026

Choose a reason for hiding this comment

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

@ArnabChatterjee20k ArnabChatterjee20k marked this pull request as draft April 8, 2026 11:42
… int and string types

- Updated `createAttribute`, `updateAttribute`, and `getColumnType` methods across various database adapters to accept `int|string` for the size parameter.
- Introduced a new private method `getSize` in the `Database` class to normalize size handling based on attribute type.
- Enhanced tests to ensure proper functionality with the updated size handling.
- Updated the validation logic in the `Attribute` class to allow for string types as valid default values for `bigint` attributes, improving type flexibility and error handling.
…ase adapters

- Updated `createAttribute`, `updateAttribute`, and `getColumnType` methods in various database adapters to require `int` for the size parameter, removing support for `string`.
- Removed the `getSize` method from the `Database` class as it is no longer needed.
- Adjusted related tests to validate the new integer-only size handling.
Comment on lines +5 to +22
class BigInt
{
public const SIGNED_MIN = '-9223372036854775808';
public const SIGNED_MAX = '9223372036854775807';
public const UNSIGNED_MAX = '18446744073709551615';

public static function isIntegerString(string $value, bool $signed = true): bool
{
return \preg_match($signed ? '/^-?\d+$/' : '/^\d+$/', $value) === 1;
}

public static function fitsPhpInt(string $value, bool $signed = true): bool
{
if (!self::isIntegerString($value, $signed)) {
return false;
}

$phpMax = (string)\PHP_INT_MAX;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's move all of this class into the validator

Comment on lines +157 to +160
case Database::VAR_INTEGER:
$size = $attributeSchema['size'] ?? 4;
$signed = $attributeSchema['signed'] ?? true;
$bits = $size >= 8 ? 64 : 32;
$bits = ($attributeType === Database::VAR_BIGINT || $size >= 8) ? 64 : 32;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The check is redundant, type is always integer here

Comment on lines +554 to +558
case Database::VAR_BIGINT:
if ($defaultType !== 'integer') {
$this->message = 'Default value ' . $default . ' does not match given type ' . $type;
throw new DatabaseException($this->message);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ArnabChatterjee20k Seems valid?

$bits = $size >= 8 ? 64 : 32;
// BIGINT is always 64-bit in SQL adapters; VAR_INTEGER uses size to decide.
$bits = ($type === Database::VAR_BIGINT || $size >= 8) ? 64 : 32;
// For 64-bit unsigned, use signed since PHP doesn't support true 64-bit unsigned
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same here, type can't be bigint if we're in the int case

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yep, was a leftover from the revert , updating

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

updated

}
break;
case Database::VAR_BIGINT:
if ($defaultType !== 'integer') {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need string here too?

$this->adapter->getMaxDateTime(),
$this->adapter->getSupportForAttributes()
$this->adapter->getSupportForAttributes(),
null,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need to pass the adapter values here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yes cause mongodb, postgres, sqlite doesn't support unsigned bigint
So for the structure validator we needed this
passing null here as current document by default is null

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