Track partner key for two-way orphan cleanup

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.
This commit is contained in:
Prem Palanisamy committed 2026-04-28 07:55:53 +01:00
1 parent 4c3965bc89
commit d37efed0d9
1 file changed
+3
+3
View File
@@ -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());
}