Skip to content

Big int#847

Open
ArnabChatterjee20k wants to merge 13 commits intomainfrom
big-init
Open

Big int#847
ArnabChatterjee20k wants to merge 13 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

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 introduces a first-class VAR_BIGINT type (bigint) to the database layer, replacing the old size-based heuristic ($size >= 8 → BIGINT) with an explicit type constant. The change touches all adapters (MariaDB, Postgres, Mongo, SQL base, Pool), the Database class, the Attribute validator, and adds corresponding tests. The architectural direction is correct and clean, but there are two runtime-breaking defects and one gap in the validator that must be addressed before merging.\n\n- P1 — PHP integer overflow in getLimitForBigInt() (SQL.php line 909, Mongo.php line 3017): the literal 18446744073709551615 (2^64 − 1) exceeds PHP_INT_MAX. PHP silently promotes it to float; returning a float from an int-typed method throws TypeError in PHP 8 at runtime.\n- P1 — VAR_BIGINT missing from validateDefaultTypes() (Attribute.php ~line 532): any bigint attribute created with a non-null default value will throw "Unknown attribute type: bigint".\n- P2 — VAR_BIGINT absent from the supportedTypes hint arrays in checkType() and validateDefaultTypes().

Confidence Score: 4/5

Not safe to merge — two P1 runtime defects will crash any code path that calls getLimitForBigInt() or sets a default on a bigint attribute.

Two P1 bugs are present: (1) the integer-overflow in getLimitForBigInt() causes a TypeError at runtime in PHP 8 for both the SQL and Mongo adapters; (2) validateDefaultTypes() is missing the VAR_BIGINT case, preventing bigint attributes from having a default value. Both must be fixed before merging.

src/Database/Adapter/SQL.php and src/Database/Adapter/Mongo.php (integer overflow), src/Database/Validator/Attribute.php (missing VAR_BIGINT case in validateDefaultTypes).

Important Files Changed

Filename Overview
src/Database/Adapter/SQL.php Adds getLimitForBigInt() returning 18446744073709551615 — this overflows PHP's int type and will throw a TypeError at runtime; fix by returning PHP_INT_MAX.
src/Database/Adapter/Mongo.php Adds VAR_BIGINT casting and schema-type mapping; getLimitForBigInt() has the same PHP integer overflow bug as SQL.php.
src/Database/Validator/Attribute.php Adds VAR_BIGINT size validation in checkType() and a backwards-compatibility fallback; however validateDefaultTypes() is missing a case for VAR_BIGINT, causing a spurious exception when a default value is set.
src/Database/Adapter/MariaDB.php Cleanly separates VAR_BIGINT into its own case instead of using the $size >= 8 heuristic; error message updated to include the new type.
src/Database/Adapter/Postgres.php Mirrors MariaDB change — VAR_BIGINT gets its own case mapping to BIGINT; error message updated accordingly.
src/Database/Database.php Adds VAR_BIGINT = 'bigint' constant and MAX_BIG_INT = PHP_INT_MAX; passes maxBigIntLength to the Attribute validator.
src/Database/Adapter/Pool.php Delegates getLimitForBigInt() to the underlying adapter — straightforward and consistent with other delegation methods.
tests/e2e/Adapter/Scopes/AttributeTests.php Adds testCreateAttributesBigIntSizeLimit() which calls getLimitForBigInt() — this test will fail with a TypeError until the integer-overflow bug in the adapters is fixed.
tests/e2e/Adapter/Scopes/DocumentTests.php Adds testCreateDocumentWithBigIntType() covering round-trip create/find for signed and unsigned bigint columns; uses Database::MAX_BIG_INT (PHP_INT_MAX) as the test value, which is correct for PHP.
tests/unit/Validator/AttributeTest.php Adds unit tests for bigint size validation; no test exercises setting a default value on a bigint attribute, which would expose the missing validateDefaultTypes case.

Comments Outside Diff (2)

  1. src/Database/Validator/Attribute.php, line 532-538 (link)

    P1 VAR_BIGINT default values always throw "Unknown attribute type" error

    validateDefaultTypes() has no case for Database::VAR_BIGINT. When a caller creates a bigint attribute with a non-null default value, execution falls through to the default: branch and throws DatabaseException: Unknown attribute type: bigint, making it impossible to set a default for any bigint attribute.

  2. src/Database/Validator/Attribute.php, line 431-441 (link)

    P2 VAR_BIGINT missing from the supportedTypes error-message list

    Both the default: branch in checkType() (line 431) and the equivalent branch in validateDefaultTypes() (line 554) build a $supportedTypes array used for error messages when an unknown type is encountered. Database::VAR_BIGINT is absent from both lists, so developers who pass an unsupported type won't see bigint in the "Must be one of …" hint.

    Consider adding Database::VAR_BIGINT after Database::VAR_INTEGER in both arrays.

Reviews (1): Last reviewed commit: "Add tests for BIGINT attribute handling ..." | Re-trigger Greptile

// 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
return 18446744073709551615;
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 PHP integer overflow — getLimitForBigInt() will throw TypeError at runtime

The literal 18446744073709551615 (2^64 − 1) exceeds PHP_INT_MAX (9223372036854775807). PHP silently promotes it to a float at parse time, and returning a float from a function declared int causes a TypeError in PHP 8. This means every call to getLimitForBigInt() — including the validator and the e2e test — will throw a TypeError at runtime.

The same overflow is present in Mongo.php at line 3017.

The project already defines Database::MAX_BIG_INT = PHP_INT_MAX (the signed 64-bit maximum). The safest representable value is PHP_INT_MAX.

Suggested change
return 18446744073709551615;
return PHP_INT_MAX;

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.

but isn't this will cause issues? cause unsinged big int is of size 18446744073709551615

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You're right that it creates a limitation, but it's unavoidable in PHP.

The core problem: PHP integers are always signed. On 64-bit systems, PHP can only represent integers from -2^63 to 2^63 - 1 (PHP_INT_MAX = 9223372036854775807). Any integer literal larger than that becomes a float at parse time, and returning a float from a function declared int throws a TypeError in PHP 8+.

The tradeoff:

  • Current code: Returns 18446744073709551615 (becomes a float) → crashes with TypeError
  • Using PHP_INT_MAX: Limits range to signed 64-bit → works, but can't use full unsigned range

Practical impact:
If you store values > PHP_INT_MAX in the database, PHP code can't manipulate them as integers anyway (they'll be floats, which lose precision at that scale). So limiting validation to PHP_INT_MAX matches what PHP can actually handle.

If you need the full unsigned range:

  1. Change return type to string: public function getLimitForBigInt(): string and return "18446744073709551615"
  2. Update validators to use bccomp() for comparison instead of numeric operators
  3. Document that BIGINT values must be handled as strings in PHP

What's your preference—limit to PHP_INT_MAX (simpler, matches PHP's integer type) or support full range with strings (more complex, requires string handling)?

public function getLimitForBigInt(): int
{
// Mongo does not handle integers directly, so using MariaDB limit for now
return 18446744073709551615;
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 PHP integer overflow — same TypeError as in SQL.php

18446744073709551615 is larger than PHP_INT_MAX and will be promoted to a float by PHP. Returning it from an int-typed function throws a TypeError in PHP 8.

Suggested change
return 18446744073709551615;
return PHP_INT_MAX;

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.
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