Ignore duplicate on create collection

This commit is contained in:
Jake Barnby 2025-05-16 22:06:59 +12:00
parent fa3894ef1c
commit d6fd05866a
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C

View file

@ -158,7 +158,7 @@ abstract class Migration
continue;
}
Console::log('Migrating collection ' . $collection['$id'] . '...');
Console::log('Migrating documents for collection "' . $collection['$id'] . '"');
$this->dbForProject->foreach($collection['$id'], function(Document $document) use ($collection, $callback) {
if (empty($document->getId()) || empty($document->getCollection())) {
@ -204,17 +204,23 @@ abstract class Migration
};
if (!$this->dbForProject->getCollection($id)->isEmpty()) {
$attributes = [];
$indexes = [];
$collection = $this->collections[$collectionType][$id];
$attributes = [];
foreach ($collection['attributes'] as $attribute) {
$attributes[] = new Document($attribute);
}
$indexes = [];
foreach ($collection['indexes'] as $index) {
$indexes[] = new Document($index);
}
$this->dbForProject->createCollection($name, $attributes, $indexes);
try {
$this->dbForProject->createCollection($name, $attributes, $indexes);
} catch (Duplicate ) {
Console::warning('Failed to create collection "' . $name . '": Collection already exists');
}
}
}