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
4 changes: 2 additions & 2 deletions src/Database/Adapter/SQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ public function getAttributeWidth(Document $collection): int
break;

case Database::VAR_RELATIONSHIP:
// INT(11)
$total += 4;
// VARCHAR(255)
$total += Database::LENGTH_KEY * 4 + 2;
break;

case Database::VAR_DATETIME:
Expand Down
19 changes: 3 additions & 16 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -2169,22 +2169,6 @@ public function createRelationship(
}
}

if (
$this->adapter->getLimitForAttributes() > 0 &&
($this->adapter->getCountOfAttributes($collection) >= $this->adapter->getLimitForAttributes()
|| $this->adapter->getCountOfAttributes($relatedCollection) >= $this->adapter->getLimitForAttributes())
) {
throw new LimitException('Column limit reached. Cannot create new attribute.');
}

if (
$this->adapter->getDocumentSizeLimit() > 0 &&
($this->adapter->getAttributeWidth($collection) >= $this->adapter->getDocumentSizeLimit()
|| $this->adapter->getAttributeWidth($relatedCollection) >= $this->adapter->getDocumentSizeLimit())
) {
throw new LimitException('Row width limit reached. Cannot create new attribute.');
}

$relationship = new Document([
'$id' => ID::custom($id),
'key' => $id,
Expand Down Expand Up @@ -2217,6 +2201,9 @@ public function createRelationship(
],
]);

$this->checkAttribute($collection, $relationship);
$this->checkAttribute($relatedCollection, $twoWayRelationship);

$collection->setAttribute('attributes', $relationship, Document::SET_TYPE_APPEND);
$relatedCollection->setAttribute('attributes', $twoWayRelationship, Document::SET_TYPE_APPEND);

Expand Down
53 changes: 53 additions & 0 deletions tests/e2e/Adapter/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,59 @@ public function testSchemaAttributes(): void
}
}

public function testRowSizeToLarge(): void
{
if (static::getDatabase()->getAdapter()->getDocumentSizeLimit() === 0) {
$this->expectNotToPerformAssertions();
return;
}
/**
* getDocumentSizeLimit = 65535
* 65535 / 4 = 16383 MB4
*/
$collection_1 = static::getDatabase()->createCollection('row_size_1');
$collection_2 = static::getDatabase()->createCollection('row_size_2');

$this->assertEquals(true, static::getDatabase()->createAttribute($collection_1->getId(), 'attr_1', Database::VAR_STRING, 16000, true));

try {
static::getDatabase()->createAttribute($collection_1->getId(), 'attr_2', Database::VAR_STRING, Database::LENGTH_KEY, true);
$this->fail('Failed to throw exception');
} catch (Exception $e) {
$this->assertInstanceOf(LimitException::class, $e);
}

/**
* Relation takes length of Database::LENGTH_KEY so exceeding getDocumentSizeLimit
*/

try {
static::getDatabase()->createRelationship(
collection: $collection_2->getId(),
relatedCollection: $collection_1->getId(),
type: Database::RELATION_ONE_TO_ONE,
twoWay: true,
);

$this->fail('Failed to throw exception');
} catch (Exception $e) {
$this->assertInstanceOf(LimitException::class, $e);
}

try {
static::getDatabase()->createRelationship(
collection: $collection_1->getId(),
relatedCollection: $collection_2->getId(),
type: Database::RELATION_ONE_TO_ONE,
twoWay: true,
);

$this->fail('Failed to throw exception');
} catch (Exception $e) {
$this->assertInstanceOf(LimitException::class, $e);
}
}

public function testCreateDeleteAttribute(): void
{
static::getDatabase()->createCollection('attributes');
Expand Down
Loading