Skip to content

Commit b0d2b9c

Browse files
committed
Improve backup policy migration error handling
1 parent 818e9f8 commit b0d2b9c

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

src/Migration/Destinations/Appwrite.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,10 +1498,9 @@ public function importBackupResource(Resource $resource): Resource
14981498
$collection = match ($resource->getResourceType()) {
14991499
Resource::TYPE_DATABASE => 'databases',
15001500
Resource::TYPE_BUCKET => 'buckets',
1501-
default => null, // Only databases and buckets support per-resource backup policies
1501+
default => null,
15021502
};
15031503

1504-
// Only pass resourceId for supported resource types
15051504
if ($collection !== null) {
15061505
$doc = $this->database->getDocument($collection, $resource->getResourceId());
15071506
if ($doc->isEmpty()) {
@@ -1514,6 +1513,12 @@ public function importBackupResource(Resource $resource): Resource
15141513
}
15151514

15161515
$params['resourceId'] = $resource->getResourceId();
1516+
} elseif ($resource->getResourceType()) {
1517+
// Per-resource backup policies only supported for databases and buckets
1518+
$resource->setStatus(
1519+
Resource::STATUS_WARNING,
1520+
'Per-resource backup policies not supported for resource type: ' . $resource->getResourceType() . '. Created as service-level policy instead.'
1521+
);
15171522
}
15181523
}
15191524

src/Migration/Sources/Appwrite.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,8 +1651,16 @@ private function reportBackups(array $resources, array &$report, array $resource
16511651
]);
16521652

16531653
$report[Resource::TYPE_BACKUP_POLICY] = $response['total'] ?? 0;
1654-
} catch (\Throwable) {
1655-
// Backup policies are Cloud-only, skip gracefully for self-hosted
1654+
} catch (\Throwable $e) {
1655+
$body = \json_decode($e->getMessage(), true);
1656+
$code = $body['code'] ?? 0;
1657+
1658+
// Re-throw permission errors as they indicate configuration issues
1659+
if ($code === 401 || $code === 403) {
1660+
throw new \Exception('Missing permission to access backup policies: ' . $e->getMessage(), previous: $e);
1661+
}
1662+
1663+
// Feature not available (404/501) - skip gracefully for self-hosted
16561664
$report[Resource::TYPE_BACKUP_POLICY] = 0;
16571665
}
16581666
}

0 commit comments

Comments
 (0)