Skip to content

Commit

Permalink
Merge pull request #58 from utopia-php/0.6.x-fix-structore-validation
Browse files Browse the repository at this point in the history
0.6.x fix structure validation
  • Loading branch information
christyjacob4 authored Nov 26, 2024
2 parents 9a8c905 + ed73513 commit 68d9b0a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Migration/Destinations/Appwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,31 @@ protected function createDocument(Document $resource, bool $isLast): bool
$databaseInternalId = $database->getInternalId();
$collectionInternalId = $collection->getInternalId();

/**
* This is in case an attribute was deleted from Appwrite attributes collection but was not deleted from the table
* When creating an archive we select * which will include orphan attribute from the schema
*/
foreach ($this->documentBuffer as $document) {
foreach ($document as $key => $value) {
if (\str_starts_with($key, '$')) {
continue;
}

/** @var $attribute \Utopia\Database\Document */
$found = false;
foreach ($collection->getAttribute('attributes', []) as $attribute) {
if ($attribute->getAttribute('key') == $key) {
$found = true;
break;
}
}

if (! $found) {
$document->removeAttribute($key);
}
}
}

$this->database->skipRelationshipsExistCheck(fn () => $this->database->createDocuments(
'database_' . $databaseInternalId . '_collection_' . $collectionInternalId,
$this->documentBuffer
Expand Down

0 comments on commit 68d9b0a

Please sign in to comment.