Skip to content

Add backup policy migration support#163

Merged
abnegate merged 5 commits intomainfrom
backup-migration-multitype
Apr 30, 2026
Merged

Add backup policy migration support#163
abnegate merged 5 commits intomainfrom
backup-migration-multitype

Conversation

@premtsd-code
Copy link
Copy Markdown
Contributor

@premtsd-code premtsd-code commented Mar 12, 2026

Summary

  • Add backup-policy resource type and backups group to the migration framework
  • Add Policy resource class with properties: id, name, services, retention, schedule, enabled, resourceId, resourceType
  • Add no-op stubs in CE source/destination (backup policies are Cloud-only)
  • Add exportGroupBackups abstract method to Source with implementations in all source classes

Test plan

  • Unit tests for Policy resource serialization
  • E2E test: migrate backup policies between Cloud projects
  • Verify no-op behavior on CE (self-hosted)
  • Verify other migration sources (Firebase, NHost, CSV, JSON) don't break

Summary by CodeRabbit

  • New Features
    • Added backup policy support to the migration system.
    • Backup policies are now a recognized transferable resource type.
    • Sources can export backups and destinations can import backup policies during migrations.
  • Tests
    • Migration tests updated to include backup policy export paths.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 12, 2026

Walkthrough

Adds backup policy support across the migration system. Introduces Resource::TYPE_BACKUP_POLICY and a new Backups Policy resource class modeling backup policies. Adds Transfer backup group constants and integrates backups into resource extraction and public lists. Extends Source with getBackupsBatchSize and an abstract exportGroupBackups; concrete sources (Appwrite, CSV, Firebase, JSON, NHost, MockSource) add exportGroupBackups handlers (Appwrite imports via importBackupResource which marks resources skipped). Source reporting and supported-resources lists updated to include backups.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% 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 PR title 'Add backup policy migration support' directly and clearly summarizes the main change: introducing backup policy migration functionality to the framework.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch backup-migration-multitype
📝 Coding Plan
  • Generate coding plan for human review comments

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
Copy Markdown
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

🧹 Nitpick comments (1)
src/Migration/Sources/Appwrite.php (1)

1426-1437: Consider surfacing the Cloud-only no-op when backups are requested.

exportGroupBackups() currently does a silent no-op. If backups are explicitly requested on CE, a non-fatal warning/log would improve operator feedback during migration runs.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Migration/Sources/Appwrite.php` around lines 1426 - 1437,
exportGroupBackups currently silently no-ops; change it to emit a non-fatal
warning when invoked so operators know backups are Cloud-only (reference: method
exportGroupBackups). Use the class logger (e.g. $this->logger or the existing
logging facility in this class) to log a clear warning indicating backups are
Cloud-only and will not be exported for CE, include any relevant group
identifier/parameters if available. Also augment reportBackups (reference:
reportBackups and Resource::TYPE_BACKUP_POLICY) to log a brief informational
message when backup policies are requested and you populate the report with
zero, so the migration report plus logs both surface that backups are
unsupported on CE.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/Migration/Destinations/Appwrite.php`:
- Around line 1490-1495: The importBackupResource(Resource $resource): Resource
method currently sets Resource::STATUS_SUCCESS without performing any import;
change it to mark the resource as skipped or warning (e.g.,
Resource::STATUS_SKIPPED or Resource::STATUS_WARNING) and attach a clear message
like "Import not implemented" (or similar), and avoid returning success until
real import logic is implemented; update the method in the Appwrite migration
class (importBackupResource) to set the non-success status and message and
optionally log the skipped action so reports/do-not-report logic won't treat it
as migrated.

In `@src/Migration/Resources/Backups/Policy.php`:
- Around line 37-48: The fromArray() factory (Policy::fromArray) currently
assumes $array['id'] exists; add explicit validation for the required id: check
isset($array['id']) and that it's the expected type/format (e.g., non-empty
string or integer) and throw a clear InvalidArgumentException (or similar) if
missing/invalid so callers get a descriptive validation error instead of a PHP
notice; then pass the validated/casted id into new self(...) as before.

---

Nitpick comments:
In `@src/Migration/Sources/Appwrite.php`:
- Around line 1426-1437: exportGroupBackups currently silently no-ops; change it
to emit a non-fatal warning when invoked so operators know backups are
Cloud-only (reference: method exportGroupBackups). Use the class logger (e.g.
$this->logger or the existing logging facility in this class) to log a clear
warning indicating backups are Cloud-only and will not be exported for CE,
include any relevant group identifier/parameters if available. Also augment
reportBackups (reference: reportBackups and Resource::TYPE_BACKUP_POLICY) to log
a brief informational message when backup policies are requested and you
populate the report with zero, so the migration report plus logs both surface
that backups are unsupported on CE.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c038b0e9-982e-4e7e-a15b-4ab24f9c9d3f

📥 Commits

Reviewing files that changed from the base of the PR and between 95dcbb9 and d3084fb.

📒 Files selected for processing (10)
  • src/Migration/Destinations/Appwrite.php
  • src/Migration/Resource.php
  • src/Migration/Resources/Backups/Policy.php
  • src/Migration/Source.php
  • src/Migration/Sources/Appwrite.php
  • src/Migration/Sources/CSV.php
  • src/Migration/Sources/Firebase.php
  • src/Migration/Sources/JSON.php
  • src/Migration/Sources/NHost.php
  • src/Migration/Transfer.php

Comment thread src/Migration/Destinations/Appwrite.php
Comment thread src/Migration/Resources/Backups/Policy.php
Copy link
Copy Markdown
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.

♻️ Duplicate comments (1)
src/Migration/Destinations/Appwrite.php (1)

1490-1495: ⚠️ Potential issue | 🟡 Minor

Include a skip reason when backup import is not implemented.

Line 1492 sets STATUS_SKIPPED without context. This makes migration reports harder to interpret when backups are intentionally no-op.

Proposed fix
 public function importBackupResource(Resource $resource): Resource
 {
-    $resource->setStatus(Resource::STATUS_SKIPPED);
+    $resource->setStatus(
+        Resource::STATUS_SKIPPED,
+        'Backup policy import is not implemented for this destination'
+    );
 
     return $resource;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Migration/Destinations/Appwrite.php` around lines 1490 - 1495, In
importBackupResource (class Appwrite) you should still mark the resource skipped
but also record a human-readable skip reason; after setting
Resource::STATUS_SKIPPED call a method on the Resource to record the reason
(e.g. $resource->setSkipReason('backup import not implemented for Appwrite')) so
migration reports show context — if Resource has no setSkipReason, add the
reason to resource metadata (e.g. $resource->setMeta('skip_reason', 'backup
import not implemented for Appwrite')) and return the resource.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/Migration/Destinations/Appwrite.php`:
- Around line 1490-1495: In importBackupResource (class Appwrite) you should
still mark the resource skipped but also record a human-readable skip reason;
after setting Resource::STATUS_SKIPPED call a method on the Resource to record
the reason (e.g. $resource->setSkipReason('backup import not implemented for
Appwrite')) so migration reports show context — if Resource has no
setSkipReason, add the reason to resource metadata (e.g.
$resource->setMeta('skip_reason', 'backup import not implemented for Appwrite'))
and return the resource.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4aa7918e-6e48-4aa6-906c-b2e688117d89

📥 Commits

Reviewing files that changed from the base of the PR and between d3084fb and 5352a2b.

📒 Files selected for processing (2)
  • src/Migration/Destinations/Appwrite.php
  • tests/Migration/Unit/Adapters/MockSource.php

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 30, 2026

Greptile Summary

This PR adds a backup-policy resource type and backups group to the migration framework, including a new Policy resource class, no-op stubs in CE source/destination (since backup policies are Cloud-only), and the exportGroupBackups abstract method implemented across all source adapters.

  • P1 – Policy::fromArray missing null guard on id: $array['id'] is accessed without ?? '', unlike every other field in the same call. A missing id key will cause a TypeError at runtime.

Confidence Score: 4/5

Safe to merge after fixing the missing null-coalescing guard on id in Policy::fromArray.

One P1 defect in Policy::fromArray where $array['id'] lacks a ?? '' fallback, which can cause a TypeError when id is absent. All other changes follow existing patterns correctly and the framework integration is complete.

src/Migration/Resources/Backups/Policy.php — the fromArray method needs the id null guard fixed before merge.

Important Files Changed

Filename Overview
src/Migration/Resources/Backups/Policy.php New Policy resource class; fromArray is missing a ?? '' guard on the id key (P1), and getEnabled() should follow the is prefix convention for booleans (P2).
src/Migration/Destinations/Appwrite.php Adds TYPE_BACKUP_POLICY to supported resources and a no-op importBackupResource stub that marks resources as STATUS_SKIPPED; pattern is consistent with the Cloud-only rationale.
src/Migration/Source.php Adds GROUP_BACKUPS to the resource-group mapping and getBackupsBatchSize() following the existing pattern for all other group types; no issues.
src/Migration/Transfer.php Adds GROUP_BACKUPS, GROUP_BACKUPS_RESOURCES, and TYPE_BACKUP_POLICY to ALL_PUBLIC_RESOURCES and the group match expression; integration is complete and consistent.
tests/Migration/Unit/Adapters/MockSource.php Adds TYPE_BACKUP_POLICY to supported resources and exportGroupBackups following the same pattern as all other export group implementations; no issues.
src/Migration/Sources/Appwrite.php No-op exportGroupBackups and reportBackups stubs added for CE; intentional per PR description, consistent with the Cloud-only policy.
src/Migration/Sources/CSV.php No-op stub throwing Not Implemented matches existing pattern for unsupported sources.
src/Migration/Sources/Firebase.php No-op stub throwing Not implemented matches existing pattern for unsupported sources.
src/Migration/Sources/JSON.php No-op stub throwing Not Implemented matches existing pattern for unsupported sources.
src/Migration/Sources/NHost.php No-op stub throwing Not Implemented matches existing pattern for unsupported sources.

Reviews (1): Last reviewed commit: "Merge branch 'main' into backup-migratio..." | Re-trigger Greptile

Comment thread src/Migration/Resources/Backups/Policy.php
Comment thread src/Migration/Resources/Backups/Policy.php
@abnegate abnegate merged commit b164631 into main Apr 30, 2026
4 checks passed
@abnegate abnegate deleted the backup-migration-multitype branch April 30, 2026 08:11
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.

2 participants