Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
52 changes: 26 additions & 26 deletions src/Database/Adapter/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
";
Expand Down
8 changes: 4 additions & 4 deletions src/Database/Adapter/Postgres.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Adapter/SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
7 changes: 0 additions & 7 deletions src/Database/Validator/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/Adapter/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
}
}

Expand Down
Loading