Skip to content
Merged
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
27 changes: 17 additions & 10 deletions src/Database/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -1191,12 +1191,6 @@ public function createCollection(string $id, array $attributes = [], array $inde
}
}

$this->adapter->createCollection($id, $attributes, $indexes);

if ($id === self::METADATA) {
return new Document(self::COLLECTION);
}

// Check index limits, if given
if ($indexes && $this->adapter->getCountOfIndexes($collection) > $this->adapter->getLimitForIndexes()) {
throw new LimitException('Index limit of ' . $this->adapter->getLimitForIndexes() . ' exceeded. Cannot create collection.');
Expand All @@ -1208,18 +1202,29 @@ public function createCollection(string $id, array $attributes = [], array $inde
$this->adapter->getLimitForAttributes() > 0 &&
$this->adapter->getCountOfAttributes($collection) > $this->adapter->getLimitForAttributes()
) {
throw new LimitException('Column limit of ' . $this->adapter->getLimitForAttributes() . ' exceeded. Cannot create collection.');
throw new LimitException('Attribute limit of ' . $this->adapter->getLimitForAttributes() . ' exceeded. Cannot create collection.');
}

if (
$this->adapter->getDocumentSizeLimit() > 0 &&
$this->adapter->getAttributeWidth($collection) > $this->adapter->getDocumentSizeLimit()
) {
throw new LimitException('Row width limit of ' . $this->adapter->getDocumentSizeLimit() . ' exceeded. Cannot create collection.');
throw new LimitException('Document size limit of ' . $this->adapter->getDocumentSizeLimit() . ' exceeded. Cannot create collection.');
}
}

$createdCollection = $this->silent(fn () => $this->createDocument(self::METADATA, $collection));
$this->adapter->createCollection($id, $attributes, $indexes);

if ($id === self::METADATA) {
return new Document(self::COLLECTION);
}

try {
$createdCollection = $this->silent(fn () => $this->createDocument(self::METADATA, $collection));
} catch (Exception $e) {
$this->adapter->deleteCollection($id);
throw $e;
}

$this->trigger(self::EVENT_COLLECTION_CREATE, $createdCollection);

Expand Down Expand Up @@ -1410,6 +1415,8 @@ public function deleteCollection(string $id): bool
$this->trigger(self::EVENT_COLLECTION_DELETE, $collection);
}

$this->purgeCachedCollection($id);

return $deleted;
}

Expand Down Expand Up @@ -1521,7 +1528,7 @@ public function createAttribute(string $collection, string $id, string $type, in
// Only execute when $default is given
if (!\is_null($default)) {
if ($required === true) {
throw new DatabaseException('Cannot set a default value on a required attribute');
throw new DatabaseException('Cannot set a default value for a required attribute');
}

$this->validateDefaultTypes($type, $default);
Expand Down