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
11 changes: 10 additions & 1 deletion src/Migration/Destinations/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Utopia\Migration\Destinations;

use Appwrite\AppwriteException;
use Appwrite\Client;
use Appwrite\InputFile;
use Appwrite\Services\Databases;
Expand Down Expand Up @@ -274,7 +275,15 @@ public function importDatabaseResource(Resource $resource): Resource
break;
case Resource::TYPE_ATTRIBUTE:
/** @var Attribute $resource */
$this->createAttribute($resource);
try {
$this->createAttribute($resource);
} catch (AppwriteException $e) {
if ($e->getType() === 'attribute_already_exists') {
$resource->setStatus(Resource::STATUS_SKIPPED, 'Attribute has been already created');
} else {
throw $e;
}
}
break;
case Resource::TYPE_DOCUMENT:
/** @var Document $resource */
Expand Down
7 changes: 4 additions & 3 deletions src/Migration/Sources/Firebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ private function exportCollection(Collection $collection, int $batchSize, bool $

$nextPageToken = null;

$knownSchema = [];
$documentSchema = [];

// Transfer Documents and Calculate Schemas
while (true) {
Expand All @@ -410,8 +410,6 @@ private function exportCollection(Collection $collection, int $batchSize, bool $
break;
}

// Calculate Schema and handle subcollections
$documentSchema = [];
foreach ($result['documents'] as $document) {
if (! isset($document['fields'])) {
continue; //TODO: Transfer Empty Documents
Expand Down Expand Up @@ -480,6 +478,9 @@ private function convertDocument(Collection $collection, array $document): Docum

$documentId = explode('/', $document['name']);
$documentId = end($documentId);
// Strip non-alphanumeric except underscore and hyphen
$documentId = preg_replace("/[^A-Za-z0-9\_\-]/", '', $documentId);
$documentId = strtolower($documentId);

return new Document($documentId, $collection->getDatabase(), $collection, $data, []);
}
Expand Down