From d37efed0d977a5f0c164861e58fc807763b1115f Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 28 Apr 2026 07:55:53 +0100 Subject: [PATCH] Track partner key for two-way orphan cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Greptile #2: source-side filter (Sources/Appwrite::exportColumns) skips RELATION_SIDE_CHILD, so the partner meta-doc created inline inside the parent's createField never reaches the partner table's createField path — and therefore never gets registered with trackOrphanCandidate. If any other column on the partner table is migrated, orphan cleanup sees the partner key absent from the tracked set and deletes it, breaking the relationship's child side. Adds a trackOrphanCandidate call right after the inline createDocument so the partner key is registered against $relatedTable. Phpstan note: adding the strict-typed call inside the existing relationship block shifted phpstan's narrowing analysis and made it flag two pre-existing $relatedTable usages (createRelationship at line 957 and purgeCachedDocument at line 1004). Both are reachable only when type === VAR_RELATIONSHIP, where $relatedTable is guaranteed defined. Suppressed with @phpstan-ignore-next-line on those two specific lines. --- src/Migration/Destinations/Appwrite.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Migration/Destinations/Appwrite.php b/src/Migration/Destinations/Appwrite.php index ee70a8c4e4..c710570ecc 100644 --- a/src/Migration/Destinations/Appwrite.php +++ b/src/Migration/Destinations/Appwrite.php @@ -923,6 +923,7 @@ class Appwrite extends Destination ]); $this->dbForProject->createDocument(self::META_ATTRIBUTES, $twoWayAttribute); + $this->trackOrphanCandidate($database, $relatedTable, 'attributeKeys', $twoWayKey, $dbForDatabases); } catch (DuplicateException) { $this->dbForProject->deleteDocument(self::META_ATTRIBUTES, $column->getId()); @@ -952,6 +953,7 @@ class Appwrite extends Destination case UtopiaDatabase::VAR_RELATIONSHIP: if (!$dbForDatabases->createRelationship( collection: $this->tableCollectionId($database, $table), + // @phpstan-ignore-next-line — $relatedTable is set when type is VAR_RELATIONSHIP. relatedCollection: $this->tableCollectionId($database, $relatedTable), type: $options['relationType'], twoWay: $options['twoWay'], @@ -1000,6 +1002,7 @@ class Appwrite extends Destination } if ($type === UtopiaDatabase::VAR_RELATIONSHIP && $options['twoWay']) { + // @phpstan-ignore-next-line — $relatedTable is set when type is VAR_RELATIONSHIP. $this->dbForProject->purgeCachedDocument($this->databaseCollectionId($database), $relatedTable->getId()); }