diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index f8c1cf60d..449ac4708 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -148,49 +148,49 @@ public function createCollection(string $name, array $attributes = [], array $in $indexStrings[$key] = "{$indexType} `{$indexId}` ({$indexAttributes}),"; } + $collection = " + CREATE TABLE {$this->getSQLTable($id)} ( + _id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT, + _uid VARCHAR(255) NOT NULL, + _createdAt DATETIME(3) DEFAULT NULL, + _updatedAt DATETIME(3) DEFAULT NULL, + _permissions MEDIUMTEXT DEFAULT NULL, + PRIMARY KEY (_id), + " . \implode(' ', $attributeStrings) . " + " . \implode(' ', $indexStrings) . " + "; + if ($this->sharedTables) { - $indexSql = ' - _tenant BIGINT UNSIGNED DEFAULT NULL, - UNIQUE KEY (_uid, _tenant), + $collection .= " + _tenant INT(11) UNSIGNED DEFAULT NULL, + UNIQUE KEY _uid (_uid, _tenant), KEY _created_at (_tenant, _createdAt), KEY _updated_at (_tenant, _updatedAt), - KEY _tenant_id (_tenant, _id), - '; + KEY _tenant_id (_tenant, _id) + "; } else { - $indexSql = ' + $collection .= " UNIQUE KEY _uid (_uid), KEY _created_at (_createdAt), - KEY _updated_at (_updatedAt), - '; + KEY _updated_at (_updatedAt) + "; } - $collection = " - CREATE TABLE {$this->getSQLTable($id)} ( - `_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, - `_uid` VARCHAR(255) NOT NULL, - `_createdAt` DATETIME(3) DEFAULT NULL, - `_updatedAt` DATETIME(3) DEFAULT NULL, - `_permissions` MEDIUMTEXT DEFAULT NULL, - ".$indexSql." - ". \implode(' ', $attributeStrings) . " - ". \implode(' ', $indexStrings) . " - PRIMARY KEY (`_id`) - )"; - + $collection .= ")"; $collection = $this->trigger(Database::EVENT_COLLECTION_CREATE, $collection); $permissions = " CREATE TABLE {$this->getSQLTable($id . '_perms')} ( - `_id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, - `_type` VARCHAR(12) NOT NULL, - `_permission` VARCHAR(255) NOT NULL, - `_document` VARCHAR(255) NOT NULL, + _id int(11) UNSIGNED NOT NULL AUTO_INCREMENT, + _type VARCHAR(12) NOT NULL, + _permission VARCHAR(255) NOT NULL, + _document VARCHAR(255) NOT NULL, PRIMARY KEY (_id), "; if ($this->sharedTables) { $permissions .= " - _tenant BIGINT UNSIGNED DEFAULT NULL, + _tenant INT(11) UNSIGNED DEFAULT NULL, UNIQUE INDEX _index1 (_document, _tenant, _type, _permission), INDEX _permission (_tenant, _permission, _type) "; diff --git a/src/Database/Adapter/Postgres.php b/src/Database/Adapter/Postgres.php index 9ca80f90c..50862c620 100644 --- a/src/Database/Adapter/Postgres.php +++ b/src/Database/Adapter/Postgres.php @@ -197,11 +197,11 @@ public function createCollection(string $name, array $attributes = [], array $in $attributeStrings[] = "\"{$attrId}\" {$attrType}, "; } - $sqlTenant = $this->sharedTables ? '_tenant BIGINT DEFAULT NULL,' : ''; + $sqlTenant = $this->sharedTables ? '_tenant INTEGER DEFAULT NULL,' : ''; $collection = " CREATE TABLE {$this->getSQLTable($id)} ( - _id BIGSERIAL NOT NULL, + _id SERIAL NOT NULL, _uid VARCHAR(255) NOT NULL, ". $sqlTenant ." \"_createdAt\" TIMESTAMP(3) DEFAULT NULL, @@ -231,8 +231,8 @@ public function createCollection(string $name, array $attributes = [], array $in $permissions = " CREATE TABLE {$this->getSQLTable($id . '_perms')} ( - _id BIGSERIAL NOT NULL, - _tenant BIGINT DEFAULT NULL, + _id SERIAL NOT NULL, + _tenant INTEGER DEFAULT NULL, _type VARCHAR(12) NOT NULL, _permission VARCHAR(255) NOT NULL, _document VARCHAR(255) NOT NULL, diff --git a/src/Database/Adapter/SQL.php b/src/Database/Adapter/SQL.php index eb56e0082..725a91a50 100644 --- a/src/Database/Adapter/SQL.php +++ b/src/Database/Adapter/SQL.php @@ -1101,9 +1101,9 @@ public function getMaxVarcharLength(): int public function getMaxIndexLength(): int { /** - * $tenant bigint requires 2 index length + * $tenant int = 1 */ - return $this->sharedTables ? 766 : 768; + return $this->sharedTables ? 767 : 768; } /** diff --git a/src/Database/Validator/Index.php b/src/Database/Validator/Index.php index 0357a5abb..2270a6e0f 100644 --- a/src/Database/Validator/Index.php +++ b/src/Database/Validator/Index.php @@ -185,17 +185,10 @@ public function checkIndexLength(Document $index): bool $attributeSize = $attribute->getAttribute('size', 0); $indexLength = $lengths[$attributePosition] ?? $attributeSize; break; - case Database::VAR_FLOAT: $attributeSize = 2; // 8 bytes / 4 mb4 $indexLength = 2; break; - - case Database::VAR_INTEGER: - $attributeSize = $attribute->getAttribute('size', 0); - $indexLength = $attributeSize = $attributeSize >= 8 ? 2 : 1; // bigint - break; - default: $attributeSize = 1; // 4 bytes / 4 mb4 $indexLength = 1; diff --git a/tests/e2e/Adapter/Base.php b/tests/e2e/Adapter/Base.php index ea04be302..90298d472 100644 --- a/tests/e2e/Adapter/Base.php +++ b/tests/e2e/Adapter/Base.php @@ -1358,9 +1358,9 @@ public function testSchemaAttributes(): void if ($db->getSharedTables()) { $attribute = $attributes['_tenant']; $this->assertEquals('_tenant', $attribute['columnName']); - $this->assertEquals('bigint', $attribute['dataType']); - $this->assertEquals('20', $attribute['numericPrecision']); - $this->assertTrue(in_array($attribute['columnType'], ['bigint unsigned', 'bigint(20) unsigned'])); + $this->assertEquals('int', $attribute['dataType']); + $this->assertEquals('10', $attribute['numericPrecision']); + $this->assertTrue(in_array($attribute['columnType'], ['int unsigned', 'int(11) unsigned'])); } }