Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,7 @@ class Database
],
[
'$id' => '$tenant',
'type' => self::VAR_INTEGER,
//'type' => self::VAR_ID, // Inconsistency with other VAR_ID since this is an INT
'type' => self::VAR_ID,
'size' => 0,
Comment on lines 253 to 255
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

INTERNAL_ATTRIBUTES now says ID, but SQL _tenant DDL is still hardcoded as INT.

This change at Line 254 does not propagate to MariaDB table creation, where _tenant is still INT(11) UNSIGNED (src/Database/Adapter/MariaDB.php:161-186, bypassing getSQLType). That leaves a schema/metadata mismatch and keeps _tenant narrower than VAR_ID semantics.

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

In `@src/Database/Database.php` around lines 253 - 255, The metadata now declares
INTERNAL_ATTRIBUTES['_tenant'] as type VAR_ID but the MariaDB table DDL in
Adapter\MariaDB still hardcodes `_tenant` as INT(11) UNSIGNED, causing a
schema/metadata mismatch; update the CREATE TABLE column generation in the
MariaDB adapter (look for the code that builds the `_tenant` column in
src/Database/Adapter/MariaDB.php) to derive the SQL type via getSQLType(...)
rather than using a hardcoded INT; specifically, replace the INT(11) UNSIGNED
usage with a call to $this->getSQLType(Database::VAR_ID) (or the equivalent call
available in that class) so `_tenant` follows VAR_ID semantics, and ensure any
size/unsigned attributes or default/null handling produced by getSQLType are
preserved.

⚠️ Potential issue | 🔴 Critical

Changing $tenant to VAR_ID can break tenant matching for int tenants.

At Line 254, VAR_ID is cast to string in casting() (Line 8872+), while tenant checks use strict !== (for example, Line 1859 and Line 1895). setTenant(1) can then mismatch against stored "1" and incorrectly return “Collection not found”.

💡 Safe immediate fix
-            'type' => self::VAR_ID,
+            'type' => self::VAR_INTEGER,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'$id' => '$tenant',
'type' => self::VAR_INTEGER,
//'type' => self::VAR_ID, // Inconsistency with other VAR_ID since this is an INT
'type' => self::VAR_ID,
'size' => 0,
'$id' => '$tenant',
'type' => self::VAR_INTEGER,
'size' => 0,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Database/Database.php` around lines 253 - 255, The mapping that replaces
the tenant's actual type with self::VAR_ID causes integer tenants to be stored
as strings and later mismatched by strict checks in setTenant(); modify the code
that builds the tenant field (the array containing '$id' => '$tenant', 'type' =>
...) to preserve the tenant's native type instead of always using self::VAR_ID —
e.g., detect is_int($tenant) and set 'type' to the integer type constant (or
otherwise choose the proper VAR_* constant) and ensure the stored value remains
$tenant (so casting() and comparisons in setTenant() see the same type).

'required' => false,
'default' => null,
Expand Down
6 changes: 3 additions & 3 deletions src/Database/Validator/Structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ class Structure extends Validator
],
[
'$id' => '$tenant',
'type' => Database::VAR_INTEGER, // ? VAR_ID
'size' => 8,
'type' => Database::VAR_ID,
'size' => 0,
'required' => false,
'default' => null,
'signed' => false,
'signed' => true,
'array' => false,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
'filters' => [],
],
Expand Down
Loading