Skip to content

Add backup policy migration support#145

Open
premtsd-code wants to merge 3 commits intomainfrom
feat-backup-policy-migration
Open

Add backup policy migration support#145
premtsd-code wants to merge 3 commits intomainfrom
feat-backup-policy-migration

Conversation

@premtsd-code
Copy link
Contributor

@premtsd-code premtsd-code commented Feb 5, 2026

Summary

  • Add backup-policy as a new resource type with Policy resource model
  • Export backup policies from Appwrite source (Cloud-only, graceful skip for self-hosted)
  • Import backup policies to Appwrite destination with resource reference validation
  • Add destination scope validation for policies.read and policies.write in report()
  • Make exportGroupBackups abstract in Source base class, add stubs in CSV, Firebase, JSON, NHost sources

Test plan

  • Migrate backup policies between two Cloud projects
  • Verify migration skips gracefully when source is self-hosted
  • Verify scope validation catches missing policies.read/policies.write
  • Verify plan validation catches additional_resource_not_allowed on Starter plan
  • Verify resource reference validation when policy targets a database/bucket that doesn't exist on destination
  • Run existing migration unit tests

Summary by CodeRabbit

  • New Features
    • Added backup policy migration support—backup policies can now be exported from and imported to Appwrite instances with automatic resource associations (databases, buckets, functions).
    • Graceful error handling for environments where backup policies are unavailable based on subscription plan.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

Walkthrough

This pull request introduces backup policy support to the migration framework. Changes include defining a new BACKUP_POLICY resource type, creating a Policy class to model backup policies with properties like name, services, retention, and schedule. The base Source and Destination classes are extended with backup-related methods. Appwrite source and destination are fully implemented with backup export/import logic including API calls and error handling. Four other migration sources (CSV, Firebase, JSON, NHost) receive stub exportGroupBackups methods that throw "Not Implemented". Test adapters are updated to recognize the new resource type and support backup export workflows.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.54% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add backup policy migration support' accurately summarizes the primary change in the pull request, which introduces backup policy migration functionality across source and destination adapters.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-backup-policy-migration

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@src/Migration/Destinations/Appwrite.php`:
- Around line 213-240: The POST check for backup policy scope (in the block
guarded by Resource::TYPE_BACKUP_POLICY where call() is used against
'/backups/policies' and the $scope variable is set) currently only treats 401s
specially; update the catch in that try/catch to also handle 400 and 404 status
codes: decode the error body from $e->getMessage(), and if the code is 400 or
404, swallow the error (treat as non-fatal so migrations continue) while
preserving other behavior for 401 (keep the existing
additional_resource_not_allowed handling and Missing scope exception); leave
other throw behavior unchanged. Ensure the logic references the same $scope
variable and call() invocations so it applies to the POST validation.

In `@src/Migration/Sources/Appwrite.php`:
- Around line 184-185: The current generic exception handler around backup
policy reporting masks permission errors; update the catch block inside the
Appwrite migration code that calls reportBackups (the code that uses
filterByIdArray() with $resourceIds) to inspect the exception type/code: if the
exception indicates an authorization/permission failure (HTTP 401 or 403 from
the Appwrite client exception), surface or rethrow it (or log it as a permission
error) so missing policies.read scope is visible; for other errors (404/501 or
other API-unavailable cases) continue to treat it as "0 policies" as before. Use
the exception's getCode()/getStatusCode() and the reportBackups/filterByIdArray
symbols to locate the handler and implement the conditional handling
accordingly.

Comment on lines +184 to 185
$this->reportBackups($resources, $report, $resourceIds);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Distinguish between API availability errors and permission errors in backup policy reporting.

The backup policy reporting uses a generic catch-all error handler (line 1665) that converts any exception into "0 policies", which masks permission errors (401/403) caused by missing policies.read scope. Since Appwrite Cloud may return different error codes than self-hosted (e.g., 404/501 for unsupported features vs. 401/403 for missing permissions), the error handling should distinguish between these cases and surface permission errors appropriately.

Note: $resourceIds is actually used via filterByIdArray() on line 1598, so no change is needed for that parameter.

Applies to: lines 1640-1669

🤖 Prompt for AI Agents
In `@src/Migration/Sources/Appwrite.php` around lines 184 - 185, The current
generic exception handler around backup policy reporting masks permission
errors; update the catch block inside the Appwrite migration code that calls
reportBackups (the code that uses filterByIdArray() with $resourceIds) to
inspect the exception type/code: if the exception indicates an
authorization/permission failure (HTTP 401 or 403 from the Appwrite client
exception), surface or rethrow it (or log it as a permission error) so missing
policies.read scope is visible; for other errors (404/501 or other
API-unavailable cases) continue to treat it as "0 policies" as before. Use the
exception's getCode()/getStatusCode() and the reportBackups/filterByIdArray
symbols to locate the handler and implement the conditional handling
accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant